Incorrect syntax was encountered while parsing GO.

Posted on : 03-01-2012 | By : Devi Prasad | In : SQL Server Issues, SQLServerPedia Syndication

Share:

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:

SELECT 'A'
GO /*Completed the batch*/

The code looks perfectly fine but when you parse it you get the fatal error shown above. 🙁

Now try parsing this piece of code:

SELECT 'A'
GO --Completed the batch

This code parses successfully. 🙂

You get same error when you parse the below code:

SELECT 'A' SELECT 'B'
GO SELECT 'C'

The code given below works fine, it runs the select statements in the batch for 4 times.

SELECT 'A' SELECT 'B'
GO 4

But this code fails while parsing:

SELECT 'A' SELECT 'B'
GO 4 /*Execute the batch  times%

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

(Visited 1,927 times, 1 visits today)



References : Devi Prasad (sqlserverlearner.com)

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.


Do you like my blog?

If you liked reading this blog, please help spread the word by sharing this blog with your friends.




Write a comment



Tags: , , , , , , , , , ,