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

Leave a Reply

Your email address will not be published. Required fields are marked *