I need to execute a command string with using GO command at the end like
exec('SELECT * FROM tblTmp where Id = 1 GO')
After executing I have
Incorrect syntax near 'GO'.
If I execute exec('SELECT * FROM tblTmp GO')
everything is OK
What's the issue here?
Thank you.
GO
is not an SQL
command, it is a batch separator understood by clients like osql
, sqlcmd
, and SSMS
but not the engine itself.
If you write something like this in SSMS
:
SELECT 1
GO
SELECT 2
GO
, the engine sends two batches with one statement in each instead of one batch with two statements.
In your second query, GO
is treated as an alias to the table tblTmp
.
Just remove GO
from your query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With