-
syntax error
Hi, hope someone can spend a minute checking out my script error. The following is part of my SQL statement. It has got syntax error near "="
I was hoping the script could run 100 times and print number 1 to 100.
DECLARE @ID int
SET @id = 1
EXEC (' WHILE ' + @id + ' <= 100 ' + ' BEGIN SELECT ' + @id +
' SET ' + @id + ' = ' + @id + ' + 1 ' + ' END ' )
Any input is most welcome.
Richard
-
syntax error (reply)
Try this
DECLARE @ID int
SET @id = 1
WHILE ( @id <= 100 )
BEGIN
print @id
set @id = @id + 1
END
-N Shah
------------
Richard Ding at 3/27/01 10:21:47 AM
Hi, hope someone can spend a minute checking out my script error. The following is part of my SQL statement. It has got syntax error near "="
I was hoping the script could run 100 times and print number 1 to 100.
DECLARE @ID int
SET @id = 1
EXEC (' WHILE ' + @id + ' <= 100 ' + ' BEGIN SELECT ' + @id +
' SET ' + @id + ' = ' + @id + ' + 1 ' + ' END ' )
Any input is most welcome.
Richard
-
syntax error (reply)
try select @id=1
and select @id=@id+1
------------
N Shah at 3/27/01 10:47:43 AM
Try this
DECLARE @ID int
SET @id = 1
WHILE ( @id <= 100 )
BEGIN
print @id
set @id = @id + 1
END
-N Shah
------------
Richard Ding at 3/27/01 10:21:47 AM
Hi, hope someone can spend a minute checking out my script error. The following is part of my SQL statement. It has got syntax error near "="
I was hoping the script could run 100 times and print number 1 to 100.
DECLARE @ID int
SET @id = 1
EXEC (' WHILE ' + @id + ' <= 100 ' + ' BEGIN SELECT ' + @id +
' SET ' + @id + ' = ' + @id + ' + 1 ' + ' END ' )
Any input is most welcome.
Richard
-
syntax error (reply)
Thank you all for reply. I forgot to mention that due to limitation of other variables, I have to use EXEC ('...' format to expose all variables outside of quotation marks. It is actually a cursor that runs through hundreds of database names and I want the script to run in each cycle. EXEC () plus variables is still a pain in the neck even though I have gathered some experiences about it.
Richard
------------
Jim at 3/27/01 10:53:24 AM
try select @id=1
and select @id=@id+1
------------
N Shah at 3/27/01 10:47:43 AM
Try this
DECLARE @ID int
SET @id = 1
WHILE ( @id <= 100 )
BEGIN
print @id
set @id = @id + 1
END
-N Shah
------------
Richard Ding at 3/27/01 10:21:47 AM
Hi, hope someone can spend a minute checking out my script error. The following is part of my SQL statement. It has got syntax error near "="
I was hoping the script could run 100 times and print number 1 to 100.
DECLARE @ID int
SET @id = 1
EXEC (' WHILE ' + @id + ' <= 100 ' + ' BEGIN SELECT ' + @id +
' SET ' + @id + ' = ' + @id + ' + 1 ' + ' END ' )
Any input is most welcome.
Richard
-
syntax error (reply)
the syntax is in your WHILE statement. You have to use "WHILE ( @id < 100 oR @id = 100)". SQL Server use different syntax for <=, >= then most program language do. Hope this helps!
Jun
------------
at 3/27/01 11:27:00 AM
Thank you all for reply. I forgot to mention that due to limitation of other variables, I have to use EXEC ('...' format to expose all variables outside of quotation marks. It is actually a cursor that runs through hundreds of database names and I want the script to run in each cycle. EXEC () plus variables is still a pain in the neck even though I have gathered some experiences about it.
Richard
------------
Jim at 3/27/01 10:53:24 AM
try select @id=1
and select @id=@id+1
------------
N Shah at 3/27/01 10:47:43 AM
Try this
DECLARE @ID int
SET @id = 1
WHILE ( @id <= 100 )
BEGIN
print @id
set @id = @id + 1
END
-N Shah
------------
Richard Ding at 3/27/01 10:21:47 AM
Hi, hope someone can spend a minute checking out my script error. The following is part of my SQL statement. It has got syntax error near "="
I was hoping the script could run 100 times and print number 1 to 100.
DECLARE @ID int
SET @id = 1
EXEC (' WHILE ' + @id + ' <= 100 ' + ' BEGIN SELECT ' + @id +
' SET ' + @id + ' = ' + @id + ' + 1 ' + ' END ' )
Any input is most welcome.
Richard
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|