Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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
  #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.


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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.