Home All Groups Group Topic Archive Search About

SQL Server 2005 and GO issue

Author
16 Dec 2005 3:19 PM
JosephPruiett
Ok gentelemen we have come accross a little issue using the 2005 platform
which is a very strange occurance.  We can open a stored procedure that has
been saved and at the top of the SP we have the following:

USE DatabaseName
GO

Followed by if exist statment etc etc.

Well we get the following error for this SP that works fine running it in
2000.

Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'GO'.


However IF we type the exact same stored procedure from scratch the complie
works fine and there is not issue.  This is the 3rd time we have ran accross
this particular issue with the final 2005 release of MS SQL Server 2005. 
Also this issue has occured on different boxes with different configurations.

Author
16 Dec 2005 4:01 PM
Aaron Bertrand [SQL Server MVP]
> which is a very strange occurance.  We can open a stored procedure that
> has
> been saved and at the top of the SP we have the following:
>
> USE DatabaseName
> GO

Just so you know, in SQL Server 2000 and in SQL Server 2005, the stored
procedure ends right here.  GO is not valid T-SQL and will not be considered
part of the procedure; it will be used to end the CREATE PROCEDURE
statement.  Anything after that will just run, you can verify this by
checking sp_helptext ...

I have explained this here before, but my template stored procedure looks
like this, which prevents an errant GO from being assumed to be a part of
the procedure:

CREATE PROCEDURE dbo.name
    -- @Params
AS
BEGIN
    SET NOCOUNT ON;
    -- code
END
GO
Author
16 Dec 2005 4:36 PM
Tibor Karaszi
Can you reproduce this with a dead-simple proc and post what Management Studio (which I assume is
what we are talking about) generates and how you make SSMS generate that (where you click, etc). I
have difficulties following exactly what is happening. I have a hunch that SSMS can generate
incorrect line feed and/or return after or before the GO, but without seeing something (reproducing
it), I can't really say.

Show quote
"JosephPruiett" <JosephPrui***@discussions.microsoft.com> wrote in message
news:62AC98C1-3D31-465C-AF1B-579227B0EB73@microsoft.com...
> Ok gentelemen we have come accross a little issue using the 2005 platform
> which is a very strange occurance.  We can open a stored procedure that has
> been saved and at the top of the SP we have the following:
>
> USE DatabaseName
> GO
>
> Followed by if exist statment etc etc.
>
> Well we get the following error for this SP that works fine running it in
> 2000.
>
> Msg 170, Level 15, State 1, Line 1
> Line 1: Incorrect syntax near 'GO'.
>
>
> However IF we type the exact same stored procedure from scratch the complie
> works fine and there is not issue.  This is the 3rd time we have ran accross
> this particular issue with the final 2005 release of MS SQL Server 2005.
> Also this issue has occured on different boxes with different configurations.
Author
16 Dec 2005 5:51 PM
Trey Walpole
I assume that this is a script that is used to create a procedure, since
USE is not allowed in a procedure.

GO is simply a batch separator that only applies to Query Analyzer and
SSMS query tool, not valid SQL (or even T-SQL), so a script running from
anywhere else would error on the GO.

You don't say how your running it when it fails in sql2005, but if you
use the same failing method against sql2000, it should fail as well,
with the same error.

JosephPruiett wrote:
Show quote
> Ok gentelemen we have come accross a little issue using the 2005 platform
> which is a very strange occurance.  We can open a stored procedure that has
> been saved and at the top of the SP we have the following:
>
> USE DatabaseName
> GO
>
> Followed by if exist statment etc etc.
>
> Well we get the following error for this SP that works fine running it in
> 2000.
>
> Msg 170, Level 15, State 1, Line 1
> Line 1: Incorrect syntax near 'GO'.
>
>
> However IF we type the exact same stored procedure from scratch the complie
> works fine and there is not issue.  This is the 3rd time we have ran accross
> this particular issue with the final 2005 release of MS SQL Server 2005. 
> Also this issue has occured on different boxes with different configurations.
Author
16 Dec 2005 9:00 PM
Tibor Karaszi
> GO is simply a batch separator that only applies to Query Analyzer and SSMS query tool, not valid
> SQL (or even T-SQL), so a script running from anywhere else would error on the GO.

Good thinking, Trey. Perhaps the OP takes the script and runs it all through his own app...

Show quote
"Trey Walpole" <treypole@newsgroups.nospam> wrote in message
news:u6DDTjmAGHA.912@TK2MSFTNGP11.phx.gbl...
>I assume that this is a script that is used to create a procedure, since USE is not allowed in a
>procedure.
>
> GO is simply a batch separator that only applies to Query Analyzer and SSMS query tool, not valid
> SQL (or even T-SQL), so a script running from anywhere else would error on the GO.
>
> You don't say how your running it when it fails in sql2005, but if you use the same failing method
> against sql2000, it should fail as well, with the same error.
>
> JosephPruiett wrote:
>> Ok gentelemen we have come accross a little issue using the 2005 platform which is a very strange
>> occurance.  We can open a stored procedure that has been saved and at the top of the SP we have
>> the following:
>>
>> USE DatabaseName
>> GO
>>
>> Followed by if exist statment etc etc.
>>
>> Well we get the following error for this SP that works fine running it in 2000.
>>
>> Msg 170, Level 15, State 1, Line 1
>> Line 1: Incorrect syntax near 'GO'.
>>
>>
>> However IF we type the exact same stored procedure from scratch the complie works fine and there
>> is not issue.  This is the 3rd time we have ran accross this particular issue with the final 2005
>> release of MS SQL Server 2005.  Also this issue has occured on different boxes with different
>> configurations.

AddThis Social Bookmark Button