GO Part 1

  • Kenneth.Fisher

    SSCoach

    Points: 19587

    Comments posted to this topic are about the item GO Part 1

    Kenneth FisherI was once offered a wizards hat but it got in the way of my dunce cap.--------------------------------------------------------------------------------For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/[/url]Link to my Blog Post --> www.SQLStudies.com[/url]

  • Raghavendra Mudugal

    SSChampion

    Points: 10658

    Awesome. πŸ™‚ thank you Kenneth.

    1. it will insert 1 record - FROM INSERT INTO

    2. it will insert 1 record - But the count in table is 2 - from INSERT..SELECT

    3. Iteration1- Inserts 2 records - the count is 4

    4. Iteration2- Inserts 4 records - the count is 8

    5. Iteration3- Inserts 8 records - the count is 16

    6. Iteration4- Inserts 16 records - the count is 32

    AND

    7. Iteration5- Inserts 32 records - the count is 64

    Now this is where I went wrong, actually the #2's GO is the valid first iteration, so it stops at #6 which actually completes 5 iterations. (#7 is not valid)

    (so simple and yet I messed up :w00t:)

    (Just wanted to say Thank you to all, this is been the best learning experience apart from the regular routine :-))

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

  • tommyh

    SSCertifiable

    Points: 6252

    Worthless question because of the fact that you add something that doesnt really relate to the question. The key part in the question is the "GO 5" part. And by adding the select from the table in the insert you make the "GO 5" part secondary.

    /T

  • Koen Verbeeck

    SSC Guru

    Points: 258955

    tommyh (9/6/2012)


    Worthless question because of the fact that you add something that doesnt really relate to the question. The key part in the question is the "GO 5" part. And by adding the select from the table in the insert you make the "GO 5" part secondary.

    /T

    Why does it make GO 5 secondary?

    The GO 5 combined with the SELECT makes the insert a power of two, which is a nice twist on the question. The question still deals with the subject: a batch is repeated 5 times because it's followed by GO 5.

    @kenneth: very nice question to end the week.

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

  • derek.colley

    SSCrazy Eights

    Points: 8040

    Good question, thanks, and how annoying that I couldn't spot the twist until it was too late.

    Lesson: Never answer QOTW before 7am.

    ---

    Note to developers:
    CAST(SUBSTRING(CAST(FLOOR(NULLIF(ISNULL(COALESCE(1,NULL),NULL),NULL)) AS CHAR(1)),1,1) AS INT) == 1
    So why complicate your code AND MAKE MY JOB HARDER??!:crazy:

    Want to get the best help? Click here https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help (Jeff Moden)
    My blog: http://uksqldba.blogspot.com
    Visit http://www.DerekColley.co.uk to find out more about me.

  • TomThomson

    SSC Guru

    Points: 104772

    Good question.

    Two days in a row now answering early morning has proved that I shouldn't do it. Yesterday I couldn't add. Today I can't multiply (or at least I get 1*2*2*2*2*2 = 6). Evidently my brain doesn't start functioning until it has been fed and watered. :doze:

    Tom

  • TomThomson

    SSC Guru

    Points: 104772

    L' Eomot InversΓ© (9/7/2012)


    Good question.

    Two days in a row now answering early morning has proved that I shouldn't do it. Yesterday I couldn't add. Today I can't multiply (or at least I get 1*2*2*2*2*2 = 6). Evidently my brain doesn't start functioning until it has been fed and watered. :doze:

    Edit: I've just noticed a failure to normalise even to 1 NF in my comment. Two days in a row is clearly a repeating group. :rolleyes:

    Tom

  • Stuart Davies

    SSCoach

    Points: 18874

    Good question

    Nearly missed the 5 after the last go - then had to remember why it was significant

    Got my point though

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a questionThere are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan I would never join a club that would allow me as a member - Groucho Marx

  • DugyC

    Hall of Fame

    Points: 3804

    What a fun question, thanks.

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

  • Michael Lysons

    SSCertifiable

    Points: 6472

    Nice question.

    I can see both sides of the discussion above re. whether it was "worthless" or not. I do think the head-scratching (for me, at least) over how many records would be in the table takes away from whether "GO x" is valid or not.

    Then again, "Is GO x valid T-SQL?" would be a boring question.

    πŸ™‚

  • Michael Lysons

    SSCertifiable

    Points: 6472

    DugyC (9/7/2012)


    What a fun question, thanks.

    Actually, yeah it was - well said πŸ™‚

  • Koen Verbeeck

    SSC Guru

    Points: 258955

    Michael Lysons (9/7/2012)


    Then again, "Is GO x valid T-SQL?" would be a boring question.

    πŸ™‚

    And the answer is surprisingly: no.

    GO is not a TSQL statement, but a batch terminator recognised by sqlcmd, osql and SSMS.

    GO (Transact-SQL)

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

  • Gazareth

    One Orange Chip

    Points: 27737

    L' Eomot InversΓ© (9/7/2012)


    1*2*2*2*2*2 = 6

    It does equal 6! At least, that's my excuse.

  • This was removed by the editor as SPAM

  • Raghavendra Mudugal

    SSChampion

    Points: 10658

    Michael Lysons (9/7/2012)


    DugyC (9/7/2012)


    What a fun question, thanks.

    Actually, yeah it was - well said πŸ™‚

    +1

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

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

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