Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 11th, 2006, 02:29 PM
Authorized User
 
Join Date: Jun 2004
Location: York, East Yorkshire, United Kingdom.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Divide, Insert a string and append a number from t

Do I just think about doing things in a strange way? Or are these really difficult questions?

I have a number from a table lets say 8000
I need to divide the 8000 by another number lets say 50

8000 / 50 = 160

Then I need to insert a string into another table 160 times appending a number to the end, starting at 1 and ending at 160

I have not got a clue where to start.. has anyone else?

Stuart
Reply With Quote
  #2 (permalink)  
Old April 11th, 2006, 06:58 PM
Kep Kep is offline
Authorized User
 
Join Date: Aug 2003
Location: Melbourne, VIC, Australia.
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You could try something like this:-

Code:
DECLARE @loop INTEGER
DECLARE @loop_hi INTEGER

CREATE TABLE #numbers (
    row_name VARCHAR(30)
)

SELECT @loop = 1,
        @loop_hi = 8000 / 50

WHILE @loop <= @loop_hi
BEGIN
    INSERT INTO #numbers
        (row_name)
        VALUES('some string' + CAST(@loop AS VARCHAR(20)))

    SELECT @loop = @loop + 1
END
Although you probably need to limit the number of loops.

As to whether there is a better way I'd have to know more details about the problem.

Kep.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
append/insert data to xml file andhiez XML 5 April 18th, 2008 11:13 AM
Divide by Zero Error [this.Adapter.Fill(dataTable) miamikk ASP.NET 1.x and 2.0 Application Design 0 October 30th, 2006 04:26 PM
how to replace a string with another string/number crmpicco Javascript How-To 4 March 14th, 2005 12:59 PM
Append String to an ordered list item mat41 HTML Code Clinic 8 October 8th, 2004 09:25 PM
VB.NET: Convert String and append to Xml files toytoy Pro VB.NET 2002/2003 0 September 2nd, 2004 10:50 PM



All times are GMT -4. The time now is 03:08 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.