Tag Archives: A fatal scripting error occurred. Incorrect syntax was encountered while parsing GO

Sql Server Error: A fatal scripting error occurred. Incorrect syntax was encountered while parsing GO

ERROR SCENARIO

We can get exception like this if we try to execute the following statement where T-SQL statement like SELECT is on the Same line as GO Statement

GO SELECT 'Basavaraj Biradar'

RESULT:

A fatal scripting error occurred.
Incorrect syntax was encountered while parsing GO.

WHY THIS EXCEPTION?

GO is not a Transact-SQL statement, instead it is a command recognized by the Sql Server Management Studio, sqlcmd and osql utilities. These utilities send all statements after the previous GO statement and before the current GO statement as one Batch to the Sql Server engine for execution. These utilities mandates that a Transact-SQL statement cannot be on the same line as a GO command.

WHAT IS THE SOLUTION?

To resolve this issue we can move the Transact SQL Statement here the SELECT statement to the next line from the one on the GO statement line as shown in the below script:

GO 
SELECT 'Basavaraj Biradar'

RESULT:
transact-sql-statement-shouldnt-be-on-the-same-line-as-go-statement