Results 1 to 3 of 3

Thread: SQL for inserting 1000's of numbers [resolved]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    Resolved SQL for inserting 1000's of numbers [resolved]

    I want to insert values from
    712000 to 713999 into a database

    eg I want to loop through

    x = 712000
    while x < 714000
    INSERT INTO tbRoute
    (val1)
    VALUES (x)
    x = x + 1
    loop

    Can I do this in SQL (I am using SQL server), rather than having to code a trivial program.
    Thanks
    Last edited by Oliver1; Dec 21st, 2006 at 10:46 AM.

  2. #2
    Lively Member Venus's Avatar
    Join Date
    Aug 2005
    Posts
    78

    Re: SQL for inserting 1000's of numbers

    That's how I'd do it with SQL using the following syntax. I'd use the SQL Query Analyzer to run it. A tip is to double up the characters used in loop statements (xx instead of x), makes trying to track them down in code easier. Here's the syntax for SQL.

    Code:
    Declare @xx as int
    SET @xx = 712000
    WHILE (@xx < 714000)
    BEGIN
    	INSERT INTO tbRoute (val1) VALUES (@xx)
    	SET @xx = @xx + 1
    END
    Last edited by Venus; Dec 20th, 2006 at 01:17 PM.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    Re: SQL for inserting 1000's of numbers

    worked a treat thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width