a fatal scripting error – SQLSERVERLEARNER https://sqlserverlearner.com LEARN SQL SERVER ONLINE Tue, 03 Jan 2012 10:42:03 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.2 Incorrect syntax was encountered while parsing GO. https://sqlserverlearner.com/2012/01/03/incorrect-syntax-was-encountered-while-parsing-go/ https://sqlserverlearner.com/2012/01/03/incorrect-syntax-was-encountered-while-parsing-go/#respond Tue, 03 Jan 2012 10:42:03 +0000 https://sqlserverlearner.azurewebsites.net/2012/01/03/incorrect-syntax-was-encountered-while-parsing-go/ 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

]]>
https://sqlserverlearner.com/2012/01/03/incorrect-syntax-was-encountered-while-parsing-go/feed/ 0