Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Experimenting with While

Author  Topic 

jmcbride
Starting Member

24 Posts

Posted - 2003-02-04 : 11:04:21
Trying to insert some sample rows into a database. I would like to use the 'WHILE' statement (getting a grasp on sql). This is my database:


CREATE TABLE personnel (emp CHAR (10),
boss CHAR (10),
lft INTEGER NOT NULL DEFAULT 0,
rgt INTEGER NOT NULL DEFAULT 0);

Here is the code that I am trying to execute:


DECLARE @iCounter int
Set @iCounter = 1
WHILE (@iCounter <> 10)
Begin
Insert into personnel (emp,rgt,lft) values ('bill_'+Cast( @iCounter as varchar(10) ),1,1)
Go
Print 'bill'
set @iCounter=@iCounter+1
End



And I doing something wrong?

--------------------
http://www.utsa.edu/
(Joe) Joseph McBride

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2003-02-04 : 11:47:55
GO isn't really a T-SQL statement, it's a batch terminator. Putting it into the middle of a WHILE loop will definitely confuse the parser. If you remove the GO it looks to me as if it should work.




Edited by - Arnold Fribble on 02/04/2003 11:49:13
Go to Top of Page
   

- Advertisement -