25-05-2012
Go is not a SQL or Transact SQL command. Go is a command recognized by
sqlcmd and osql facilities provided by SQL server studio.
Go specifies an end to a particular SQL batch. Once the parser interprets a
Go, that block is considered completed and the following SQL are considered
as new batch till the parser finds a new Go.
For example, even though following code isn’t syntactically wrong, it won’t
work because a create procedure has to be the first statement in a batch:
if object_id('GetRRTData') is not null
drop procedure GetRRTData;
CREATE/ALTER PROCEDURE GetRRTData
@TargetDate datetime,
@NephFilter varchar (100),
@ElsewhereFilter varchar (100)
as
...
...
/* This will return following error :
* Msg 111, Level 15, State 1, Procedure GetRRTData, Line 18
* 'CREATE/ALTER PROCEDURE' must be the first statement in a query batch.
*/
You can eliminate this by breaking the SQL above the Create Procedure
Statement into a separate SQL batch using a Go.
Following code works without any complain:
if object_id('GetRRTData') is not null
drop procedure GetRRTData;
Go
CREATE/ALTER PROCEDURE GetRRTData
@TargetDate datetime,
@NephFilter varchar (100),
@ElsewhereFilter varchar (100)
as
...
...
For an in-depth knowledge on this read this msdn article
Menol