What is the result ? (SQLServer 2005)

  • Comments posted to this topic are about the item What is the result ? (SQLServer 2005)

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • What happens seems to depend on the SQL Client/Options in use, rather than which version of SQL is at the back end.

    The script executes 10 times if I run it in Management Studio, but...

    When I run it in Query Analyser (against a SQL 2005 instance), I get an error:-

    Server: Msg 102, Level 15, State 1, Line 2

    Incorrect syntax near 'GO'.

  • probably Query Analyser doesn't recognize GO [count] syntax.

    That proves that Query Analyser has it own syntax validation!

  • Keep in mind SSMS has some issues with e.g. char(13) resulting in a "syntax error near ...."

    And off course you'll need to have the default 'go' for batch separator in your ssms settings.

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • ALZDBA (9/10/2008)


    Keep in mind SSMS has some issues with e.g. char(13) resulting in a "syntax error near ...."

    And off course you'll need to have the default 'go' for batch separator in your ssms settings.

    Im sorry but no, that is not asked in the question. The question asks what that piece of code does, and the result is:

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near 'GO'.

    I was going to choose the correct answer before I tested just to see what does happen, I should of done that as I would of got the answer "correct".

  • skyline666 (9/10/2008)


    ALZDBA (9/10/2008)


    Keep in mind SSMS has some issues with e.g. char(13) resulting in a "syntax error near ...."

    And off course you'll need to have the default 'go' for batch separator in your ssms settings.

    Im sorry but no, that is not asked in the question. The question asks what that piece of code does, and the result is:

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near 'GO'.

    I was going to choose the correct answer before I tested just to see what does happen, I should of done that as I would of got the answer "correct".

    In my case, it results in the batch run 10 times. I tested in my local instalation, with the default setting.

    Probably you have some kind of customization that changed the setting for default batch seperator?

    Example: If i change default separator to ";" got Msg 170, Level 15, State 1, Line 2

    Line 2: Incorrect syntax near 'GO'.

  • You need to use SSMS (SQL 2005) to get the result aimed for with the question.

    Apparently it's SSMS that puls this trick !

    Indeed With Query Analyser, you'll get the syntax error.

    -- Query analyser SQL2000

    Server: Msg 102, Level 15, State 1, Line 5

    Incorrect syntax near 'go'.

    -- SSMS 2005

    Beginning execution loop

    Hey what's going on ?

    Hey what's going on ?

    Hey what's going on ?

    Hey what's going on ?

    Hey what's going on ?

    Hey what's going on ?

    Hey what's going on ?

    Hey what's going on ?

    Hey what's going on ?

    Hey what's going on ?

    Batch execution completed 10 times.

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • This is the right way to execute the statement without using the counter.

  • I for one, guessed wrong but I wanted to verify my answer before I submitted it. So, I highlighted and copied the code to SSMS and got the error, confirming my guess. When I was told I had the incorrect answer, I went back to SSMS and discovered that the two lines of code were mashed together on a single line:

    print 'Hey what''s going on ?';GO 10

    This produced the error. However, when I separated it to two lines, it did work as expected by the question's author:

    print 'Hey what''s going on ?';

    GO 10

  • In response to:

    -- Query analyser SQL2000

    Server: Msg 102, Level 15, State 1, Line 5

    Incorrect syntax near 'go'.

    Hi,

    you are right, this technique does not works in SQL 2000. Its works version SQL 2005 and above and same statement works in sqlcmd without any error. It repeats the batch no of times as integer value mentioned after GO statement.

  • I did the same thing, edited the single line to two lines and it worked in QA. I was wondering if anyone had ideas on how this feature (GO 10) could be used...any thoughts?

  • imagine you need to generate 100 random numbers?

    You can hit F5 100 times or use go 100.

  • barb.wendling (9/10/2008)


    I did the same thing, edited the single line to two lines and it worked in QA. I was wondering if anyone had ideas on how this feature (GO 10) could be used...any thoughts?

    Use SSMS if you want this to work !! (Not query analyser !)

    e.g. for test purposes

    create table mytable (id int not null identity(1,1) primary key,

    col2 varchar(150) not null ,

    col3 datetime not null default getdate() )

    go

    /* Fill table with 15000 rows */

    insert into mytable (col2) values ('Initial load');

    go 15000

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • e.g. for test purposes

    create table mytable (id int not null identity(1,1) primary key,

    col2 varchar(150) not null ,

    col3 datetime not null default getdate() )

    go

    /* Fill table with 15000 rows */

    insert into mytable (col2) values ('Initial load');

    go 15000

    Careful ALZDBA, you'll have the RBAR police after you for suggesting something like that.;)

  • Boo hoo :crying: - I got it wrong because my local copy of BOL (SQL 2005) doesn't have the (count) syntax in it.

Viewing 15 posts - 1 through 15 (of 36 total)

You must be logged in to reply to this topic. Login to reply