GO Part 2

  • A good and tricky one. Thank you.

  • Hugo Kornelis (9/13/2012)


    Finally, I can give you one example where this knowledge can be useful: when you have a co-worker whose idea of fun it is to change the batch seperator to, for instance, "SELECT" when you are away from your keyboard, and then watch you struggle to understand why your code is not working anymore. After this QotD, you will probably be able to recognise and fix the problem much faster than you otherwise would have.

    +1

    Few minutes ago did this on my coworker's system and provided this link qtod to solve it.... (for him I was genius.... :hehe: )

    ww; Raghu
    --
    The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.

  • Misread the true meaning of the question so got it wrong. Thanks for the followup discussion as I struggled with this one.

  • Good question

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Learned something but it was a horribly presented question. Can't believe it got through any type of quality assurance.

  • Thanks for the question. I got it right, but did so with a semi-educated guess. I reasoned that, if the answer was FALSE, this is a useless question of a type on which you can make unlimited variations. Might I suggest that a better way to express the same idea is to say something like:

    In what way can the query be made to run as written?

    A. Hop on one leg

    B. Pat your head

    C. Eat kippers for breakfast

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

  • Raghavendra Mudugal (9/13/2012)


    Hugo Kornelis (9/13/2012)


    Finally, I can give you one example where this knowledge can be useful: when you have a co-worker whose idea of fun it is to change the batch seperator to, for instance, "SELECT" when you are away from your keyboard, and then watch you struggle to understand why your code is not working anymore. After this QotD, you will probably be able to recognise and fix the problem much faster than you otherwise would have.

    +1

    Few minutes ago did this on my coworker's system and provided this link qtod to solve it.... (for him I was genius.... :hehe: )

    I'm not so brave 😛



    See, understand, learn, try, use efficient
    © Dr.Plch

  • I got the answer right but got the intention of the question wrong.

    When I thought, can I get that script to run without changing it, my method to achieve this was to run them individually as 2 separate batches by highlighting each batch minus the batch separator..

    I obviously missed the point of this question :ermm:

  • For those who are curious on how to change the batch terminator:

    http://stackoverflow.com/questions/2299249/what-is-the-use-of-go-in-sql-server-management-studio%5B/url%5D

    Best to copy and paste the above link rather than direcly clicking on it.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • arthurolcot (9/13/2012)


    I got the answer right but got the intention of the question wrong.

    When I thought, can I get that script to run without changing it, my method to achieve this was to run them individually as 2 separate batches by highlighting each batch minus the batch separator..

    I obviously missed the point of this question :ermm:

    I think that is the problem. It was very easy to miss the point of the question.

  • arthurolcot (9/13/2012)


    I got the answer right but got the intention of the question wrong.

    When I thought, can I get that script to run without changing it, my method to achieve this was to run them individually as 2 separate batches by highlighting each batch minus the batch separator..

    I obviously missed the point of this question :ermm:

    Does it matter? You solved the problem.

    Another method: Write a program in your favourite language (C#, C++ ...) that connects to the database, splits the input using notgo, and runs the separated batches.

    As all these steps aside are correct, I don't understand the majority of False answers.



    See, understand, learn, try, use efficient
    © Dr.Plch

  • Followed my usual practice of looking through the documentation, got briefly sidetracked by focusing on the two variable declarations (thinking that I needed to find a way to force the 'NotGo' to be ignored), then found the correct answer. While the wording is slightly non-standard, the question is easily understood and the correct answer wasn't THAT difficult to find. Learned something (useful or not) so this is a good day!

    Edit: Correct answer being defined as the answer given by the question author, as I see that others found different ways to solve the problem.

  • I knew the correct answer, but only because I used my mind reading skills to extract the missing part of the question.

    "Can the following script be made to run in SSMS without changes to the script and without error?"

    Yes, I can make it execute successfully in SSMS, but I can never get it to work with .NET or any other programming language.

  • Nils Gustav Stråbø (9/13/2012)


    Yes, I can make it execute successfully in SSMS, but I can never get it to work with .NET or any other programming language.

    Nor would you if the script had used "GO" instead of "NotGo", as sending a "GO" to SQL Server from .NET or other client program will also result in an error.

    You'd have to write the .NET (or other) code such to recognise the GO as a batch terminator, then send everything up to that GO as one batch, then everything following that GO as the next batch. And if you can do that with "GO" as the batch seperator, you can do so with "NotGo" too. (Though I have no idea why you'd want to).


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • I am not crazy about the wording, but I did learn about batch separators once I found where the setting was in SSMS.

    -- Go to Tools -> Options -> Change the Batch Separator to EndBatch from GO.

    Painful, but I'll get over it.

Viewing 15 posts - 16 through 30 (of 82 total)

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