• Here's my interpretation of what happens. Note if you select and execute the lines by themselves you get different results than you do if you combine them into a batch.

    1 CREATE PROC GO @GO int=NULL AS SELECT @GO -- Start a new batch

    2 GO-- This GO terminates procedure definition batch

    3 GO; -- Begin a new batch

    4 GO 3 -- Is this a SQLCMD? Ignored as a batch terminator because of the 3? Start loop.

    5 GO -- Terminate the batch

    6 EXECUTE('GO 3') -- Begin a new batch

    7 GO 3 -- Is this a SQLCMD? Ignored as a batch terminator because of the 3? Start loop.

    8 GO -- Terminate the batch

    9 DROP PROC GO -- Start a new batch to drop the proc

    10 GO -- Terminate the batch dropping the procedure

    So we have

    Batch 1 lines 1 and 2 -- Define the proc

    Batch 2 lines 3 - 5 -- Execute the proc with no parm 3 times

    Batch 3 lines 6 - 8 -- Execute the proc with parm 3 times

    Batch 4 lines 9 and 10 -- Drop the proc.