{"id":103,"date":"2012-01-03T10:42:03","date_gmt":"2012-01-03T10:42:03","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2012\/01\/03\/incorrect-syntax-was-encountered-while-parsing-go\/"},"modified":"2012-01-03T10:42:03","modified_gmt":"2012-01-03T10:42:03","slug":"incorrect-syntax-was-encountered-while-parsing-go","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2012\/01\/03\/incorrect-syntax-was-encountered-while-parsing-go\/","title":{"rendered":"Incorrect syntax was encountered while parsing GO."},"content":{"rendered":"

When you try to execute the code which has multiline comment after GO statement you get the error:<\/strong>
\n
\nA fatal scripting error occurred.
\nIncorrect syntax was encountered while parsing GO.
\n<\/font><\/p>\n

Following piece of code can be used to reproduce this error:<\/strong><\/p>\n

Try parsing this SQL Code:
\n[sql]
\nSELECT ‘A’
\nGO \/*Completed the batch*\/
\n[\/sql]<\/p>\n

The code looks perfectly fine but when you parse it you get the fatal error shown above. \ud83d\ude41<\/p>\n

Now try parsing this piece of code:
\n[sql]
\nSELECT ‘A’
\nGO –Completed the batch
\n[\/sql]<\/p>\n

This code parses successfully. \ud83d\ude42<\/p>\n

You get same error when you parse the below code:
\n[sql]
\nSELECT ‘A’ SELECT ‘B’
\nGO SELECT ‘C’
\n[\/sql]<\/p>\n

The code given below works fine, it runs the select statements in the batch for 4 times.
\n[sql]
\nSELECT ‘A’ SELECT ‘B’
\nGO 4
\n[\/sql]<\/p>\n

But this code fails while parsing:
\n[sql]
\nSELECT ‘A’ SELECT ‘B’
\nGO 4 \/*Execute the batch times%
\n[\/sql]<\/p>\n

So in general(not completely sure) SQL Parser is giving error when GO<\/strong> statement has some text following it(except — or a number)<\/p>\n

Alternate Fix:<\/strong><\/p>\n

Use single line comments(–) instead of multiline comments(\/**\/) after the GO<\/strong> statement<\/p>\n

This error is logged with microsoft in the following link: Microsoft link<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

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…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[186,3],"tags":[629,630,631,632,633,634,635,636,637,638,639],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-sql-server-issues","category-sqlserverpedia-syndication","tag-a-fatal-scripting-error","tag-a-fatal-scripting-error-occurred","tag-a-fatal-scripting-error-occurred-incorrect-syntax-was-encountered-while-parsing-go","tag-a-fatal-scripting-error-occurred-sql-server","tag-a-fatal-scripting-error-occurred-sqlcmd","tag-a-fatal-scripting-error-occurred-sqlserver","tag-error-with-multiline-comment-after-go-statement","tag-fatal-scripting-error","tag-incorrect-syntax-was-encountered-while-parsing","tag-incorrect-syntax-was-encountered-while-parsing-error","tag-incorrect-syntax-was-encountered-while-parsing-go"],"_links":{"self":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":0,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}