• Wow, tough crowd today.  Must be a Monday thing since yesterday was a day off for many folks.

    I use GO all the time in scripts, especially migration scripts as they have a mix of functions, stored procs, and SQL statements including drop and create statements many of which must be at the start of a batch.  Knowing where to put the GOs in the script make all the difference.

    One thing about GO that wasn't apparant to me when I first started TSQL was that you couldn't use a local variable that was declared "across a GO".  For instance this script gives you an error:

    --

    DECLARE @myvar varchar(100)

    GO

    SET @myvar = 'Bob was here!'

    SELECT @myvar

    --

    In such a short script it's easy to fix, but in larger scripts that need to process in a specific order, this limitation may require using temporary tables or other objects to hold values from one batch to the next.