Problem with GO | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Problem with GO


sp_pkeys ‘tt’ Go sp_pkeys ‘tt1’ – This does not work giving error Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ‘Go’. But this works sp_pkeys ‘tt’
Go
sp_pkeys ‘tt1’ Is it necessary to have GO as seperate one? Madhivanan Failing to plan is Planning to fail
From BOL
A Transact-SQL statement cannot occupy the same line as a GO command. However, the line can contain comments.
Hi madhivanan, even this will raise error
sp_pkeys ‘tt’ Go
Yes in order to seperate the statement execution GO keyword must be used.
In this case Stored procedure will come handy. Satya SKJ
Moderator
http://www.SQL-Server-Performance.Com/forum
This posting is provided “AS IS” with no rights for the sake of knowledge sharing.
Why Satya? I’m a little confused. Wouldn’t you need to use dynamic SQL in the stored procedure if you did that? GO is a batch terminator, meaning it would effectively end the stored procedures if you tried to use it within the direct execution context of the procedure. MeanOldDBA
[email protected] When life gives you a lemon, fire the DBA.
The GO command should stand alone on its own line. Technically, you can start a new batch on the same line after the GO command, but you’ll find this puts a serious damper on readability. T-SQL statements cannot precede the GO statement, or the GO statement will often be misinterpreted and cause either a parsing error or other unexpected result. For example, if I use a GO statement after a WHERE clause:
SELECT * FROM Customers WHERE CustomerID = ‘ALFKI’ GO The parser becomes somewhat confused: [quote
sp_pkeys ‘tt’ Go sp_pkeys ‘tt1’ – This does not work giving error Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ‘Go’.

]]>