T-SQL GO statement

  • mike l

    Right there with Babe

    Points: 742

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

  • Hardy21

    SSCrazy Eights

    Points: 9708

    Nice command. Thanks

    Thanks

  • Jinx-640161

    Ten Centuries

    Points: 1078

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

    Thanks!

  • Iulian -207023

    SSCertifiable

    Points: 7507

    Good point, thanks

    Iulian

  • Koen Verbeeck

    SSC Guru

    Points: 258907

    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

  • Manoj KN

    SSC Journeyman

    Points: 80

    Nice information, thanks..

  • Mayank Parmar

    Ten Centuries

    Points: 1019

    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
    --------------------------------------------------------------------------------

  • DugyC

    Hall of Fame

    Points: 3804

    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]

  • Hardy21

    SSCrazy Eights

    Points: 9708

    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

  • RichardDouglas

    SSCarpal Tunnel

    Points: 4029

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

    Hope this helps,
    Rich

    [p]
    [/p]

  • DugyC

    Hall of Fame

    Points: 3804

    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]

  • Nils Gustav Stråbø

    SSChampion

    Points: 11259

    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

  • Hardy21

    SSCrazy Eights

    Points: 9708

    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

  • Brigadur

    SSCrazy

    Points: 2097

    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.

  • Hardy21

    SSCrazy Eights

    Points: 9708

    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 47 total)

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