Incorrect syntax was encountered while parsing GO.
Posted on : 03-01-2012 | By : Devi Prasad | In : SQL Server Issues, SQLServerPedia Syndication
0

When you try to execute the code which has multiline comment after GO statement you get the error:
A fatal scripting error occurred.
Incorrect syntax was encountered while parsing GO.
Following piece of code can be used to reproduce this error:
Try parsing this SQL Code:
[sql]
SELECT ‘A’
GO /*Completed the batch*/
[/sql]
The code looks perfectly fine but when you parse it you get the fatal error shown above. 🙁
Now try parsing this piece of code:
[sql]
SELECT ‘A’
GO –Completed the batch
[/sql]
This code parses successfully. 🙂
You get same error when you parse the below code:
[sql]
SELECT ‘A’ SELECT ‘B’
GO SELECT ‘C’
[/sql]
The code given below works fine, it runs the select statements in the batch for 4 times.
[sql]
SELECT ‘A’ SELECT ‘B’
GO 4
[/sql]
But this code fails while parsing:
[sql]
SELECT ‘A’ SELECT ‘B’
GO 4 /*Execute the batch times%
[/sql]
So in general(not completely sure) SQL Parser is giving error when GO statement has some text following it(except — or a number)
Alternate Fix:
Use single line comments(–) instead of multiline comments(/**/) after the GO statement
This error is logged with microsoft in the following link: Microsoft link
Reference : Devi Prasad (sqlserverlearner.com)
Do you like my blog?
If you liked reading this blog, please help spread the word by sharing this blog with your friends.
Need Help On SQL Server?
Cannot Find Solution to your problem (or) If you are looking for some help on SQL Server. Dont worry Click Here to Post your question and solve your issue.

Tags: a fatal scripting error, A fatal scripting error occurred, A fatal scripting error occurred Incorrect syntax was encountered while parsing GO., A fatal scripting error occurred sql server, A fatal scripting error occurred sqlcmd, A fatal scripting error occurred sqlserver, error with multiline comment after GO statement, fatal scripting error, incorrect syntax was encountered while parsing, incorrect syntax was encountered while parsing error, Incorrect syntax was encountered while parsing GO