Results 1 to 5 of 5

Thread: syntax error

  1. #1
    Richard Ding Guest

    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 (&#39; WHILE &#39; + @id + &#39; <= 100 &#39; + &#39; BEGIN SELECT &#39; + @id +
    &#39; SET &#39; + @id + &#39; = &#39; + @id + &#39; + 1 &#39; + &#39; END &#39; )

    Any input is most welcome.


    Richard

  2. #2
    N Shah Guest

    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 &#34;=&#34;
    I was hoping the script could run 100 times and print number 1 to 100.

    DECLARE @ID int
    SET @id = 1
    EXEC (&#39; WHILE &#39; + @id + &#39; <= 100 &#39; + &#39; BEGIN SELECT &#39; + @id +
    &#39; SET &#39; + @id + &#39; = &#39; + @id + &#39; + 1 &#39; + &#39; END &#39; )

    Any input is most welcome.


    Richard

  3. #3
    Jim Guest

    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 &#34;=&#34;
    I was hoping the script could run 100 times and print number 1 to 100.

    DECLARE @ID int
    SET @id = 1
    EXEC (&#39; WHILE &#39; + @id + &#39; <= 100 &#39; + &#39; BEGIN SELECT &#39; + @id +
    &#39; SET &#39; + @id + &#39; = &#39; + @id + &#39; + 1 &#39; + &#39; END &#39; )

    Any input is most welcome.


    Richard

  4. #4
    Guest

    syntax error (reply)

    Thank you all for reply. I forgot to mention that due to limitation of other variables, I have to use EXEC (&#39;...&#39 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 &#34;=&#34;
    I was hoping the script could run 100 times and print number 1 to 100.

    DECLARE @ID int
    SET @id = 1
    EXEC (&#39; WHILE &#39; + @id + &#39; <= 100 &#39; + &#39; BEGIN SELECT &#39; + @id +
    &#39; SET &#39; + @id + &#39; = &#39; + @id + &#39; + 1 &#39; + &#39; END &#39; )

    Any input is most welcome.


    Richard

  5. #5
    Jun Guest

    syntax error (reply)

    the syntax is in your WHILE statement. You have to use &#34;WHILE ( @id < 100 oR @id = 100)&#34;. 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 (&#39;...&#39 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 &#34;=&#34;
    I was hoping the script could run 100 times and print number 1 to 100.

    DECLARE @ID int
    SET @id = 1
    EXEC (&#39; WHILE &#39; + @id + &#39; <= 100 &#39; + &#39; BEGIN SELECT &#39; + @id +
    &#39; SET &#39; + @id + &#39; = &#39; + @id + &#39; + 1 &#39; + &#39; END &#39; )

    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
  •