stored procedure to populate table with numbers

Last Post 01 May 2007 11:52 AM by nnnnnpatel. 3 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
nnnnnpatel
New Member
New Member

--
01 May 2007 11:25 AM
How do you write an sql procedure statement to populate a table with 5000 number starting with 1 to 5000. My table name is tblClient and a single field called clientnumber. Sorry for asking dumb question but there must be way to do it without running the stored procdure 5000 times. Thanks


Nick
nnnnnpatel
New Member
New Member

--
01 May 2007 11:38 AM
Sorry, I should have said, is there a way to write a stored procedure to loop 5000 an insert statement vs repeating the statement 5000 lines. I'm a vfp programmer and haven't dealt with sql server much. Thanks

nick
nnnnnpatel
New Member
New Member

--
01 May 2007 11:52 AM
Thanks for answering back, I did the following:

declare @a smallint
set @a = 1
while @a <= 5000
begin
insert into tblClientNumbers (ClientNumber) values(@a)
set @a = @a + 1
end

but I keep getting this message:

=============================
Msg 208, Level 16, State 1, Line 5
Invalid object name 'tblClientNumbers'.
=============================

My table name is 'tblClientNumbers'. I even tried 'dbo.tblClientNumbers' for the table name.


thanks
Nick
nnnnnpatel
New Member
New Member

--
01 May 2007 12:19 PM
Never mind, I had to select the right database in the dropdown combobox above the query. Thanks again RM.


Nick
You are not authorized to post a reply.

Acceptable Use Policy