T-SQL GO statement

  • Comments posted to this topic are about the item T-SQL GO statement

  • Nice command. Thanks

    Thanks

  • Ha! I never knew one could do that with GO.

    Thanks!

  • Good point, thanks

    Iulian

  • I like the point the question tried to make, namely using the GO statement as an instrument to loop, but I do not like the trickery with the # name. At first, I did not even notice the GO 100 statement, as I was focusing on the table name. So I'm confused what this question actually tried to do: teach us about GO n (mission accomplished), or about the various options for table names or was it just to trick people into choosing the wrong answer?

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Nice information, thanks..

  • Good Question to ask !!!

    --------------------------------------------------------------------------------
    Mayank Parmar
    Software Engineer

    Clarion Technologies
    SEI CMMI Level 3 Company

    8th Floor, 803, GNFC info Tower,
    SG Highway, Ahmedabad - 380 054,
    Gujarat, India.
    www.clariontechnologies.co.in

    Email: mayank.parmar@clariontechnologies.co.in
    MSN : mayank.parmar@clariontechnologies.co.in
    Mobile: +91 9727748789
    --------------------------------------------------------------------------------

  • da-zero (11/23/2010)


    I like the point the question tried to make, namely using the GO statement as an instrument to loop, but I do not like the trickery with the # name. At first, I did not even notice the GO 100 statement, as I was focusing on the table name. So I'm confused what this question actually tried to do: teach us about GO n (mission accomplished), or about the various options for table names or was it just to trick people into choosing the wrong answer?

    Yeah, I fell down on this one as well... however, when I did actually try to run the code it didn't seem to like the "100"... I got...

    (1 row(s) affected)

    Server: Msg 170, Level 15, State 1, Line 3

    Line 3: Incorrect syntax near '100'.

    The code is identical... I'm running this on a SQL Server 2000 box, but I don't think that matters...

    _____________________________________________________________________
    [font="Comic Sans MS"]"The difficult tasks we do immediately, the impossible takes a little longer"[/font]

  • Try

    INSERT INTO #

    SELECT 'ASDF'

    GO 0

    GO <ZERO> --- SQL doesn't throw any complilation error but when you execute the code, status bar should display: "Query completed with errors".

    Thanks

  • Good question, thanks for taking the time to help educate the SQL community.

    Hope this helps,
    Rich

    [p]
    [/p]

  • Hardy21 (11/23/2010)


    Try

    INSERT INTO #

    SELECT 'ASDF'

    GO 0

    GO <ZERO> --- SQL doesn't throw any complilation error but when you execute the code, status bar should display: "Query completed with errors".

    Nope, doesn't like the 0 (zero) either.

    I think it is the old version of SQL... further investigation does seem to suggest it.

    _____________________________________________________________________
    [font="Comic Sans MS"]"The difficult tasks we do immediately, the impossible takes a little longer"[/font]

  • It's also worth mentioning that GO is not a T-SQL statement. It is a command only recognized by SSMS, sqlcmd and osql, so it can't be used in any T-SQL code that is not executed in any of the three applications mentioned. In other words, SQL Server does not know what GO is.

    From BOL:

    "SQL Server utilities interpret GO as a signal that they should send the current batch of Transact-SQL statements to an instance of SQL Server. The current batch of statements is composed of all statements entered since the last GO, or since the start of the ad hoc session or script if this is the first GO."

    Ref http://msdn.microsoft.com/en-us/library/ms188037.aspx

  • DougieCow (11/23/2010)


    Hardy21 (11/23/2010)


    Try

    INSERT INTO #

    SELECT 'ASDF'

    GO 0

    GO <ZERO> --- SQL doesn't throw any complilation error but when you execute the code, status bar should display: "Query completed with errors".

    Nope, doesn't like the 0 (zero) either.

    I think it is the old version of SQL... further investigation does seem to suggest it.

    I have executed the code against SQL Server 2008 R2.

    Thanks

  • Hardy21 (11/23/2010)


    DougieCow (11/23/2010)


    Hardy21 (11/23/2010)


    Try

    INSERT INTO #

    SELECT 'ASDF'

    GO 0

    GO <ZERO> --- SQL doesn't throw any complilation error but when you execute the code, status bar should display: "Query completed with errors".

    Nope, doesn't like the 0 (zero) either.

    I think it is the old version of SQL... further investigation does seem to suggest it.

    I have executed the code against SQL Server 2008 R2.

    I have also executed on SQL Server 2008 R2. It gave "Query completed with errors" but no error message.

  • Brigadur (11/23/2010)


    Hardy21 (11/23/2010)


    DougieCow (11/23/2010)


    Hardy21 (11/23/2010)


    Try

    INSERT INTO #

    SELECT 'ASDF'

    GO 0

    GO <ZERO> --- SQL doesn't throw any complilation error but when you execute the code, status bar should display: "Query completed with errors".

    Nope, doesn't like the 0 (zero) either.

    I think it is the old version of SQL... further investigation does seem to suggest it.

    I have executed the code against SQL Server 2008 R2.

    I have also executed on SQL Server 2008 R2. It gave "Query completed with errors" but no error message.

    Correct.

    Also if you execute the: select * from #

    GO 0 then also it should display: "Query completed with errors" in status bar, and doesn't display any data in grid due to code is not executed.

    Thanks

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

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