{"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> Following piece of code can be used to reproduce this error:<\/strong><\/p>\n Try parsing this SQL Code: 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: This code parses successfully. \ud83d\ude42<\/p>\n You get same error when you parse the below code: The code given below works fine, it runs the select statements in the batch for 4 times. But this code fails while parsing: 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
\n
\nA fatal scripting error occurred.
\nIncorrect syntax was encountered while parsing GO.
\n<\/font><\/p>\n
\n[sql]
\nSELECT ‘A’
\nGO \/*Completed the batch*\/
\n[\/sql]<\/p>\n
\n[sql]
\nSELECT ‘A’
\nGO –Completed the batch
\n[\/sql]<\/p>\n
\n[sql]
\nSELECT ‘A’ SELECT ‘B’
\nGO SELECT ‘C’
\n[\/sql]<\/p>\n
\n[sql]
\nSELECT ‘A’ SELECT ‘B’
\nGO 4
\n[\/sql]<\/p>\n
\n[sql]
\nSELECT ‘A’ SELECT ‘B’
\nGO 4 \/*Execute the batch times%
\n[\/sql]<\/p>\n