While it is bad practice on the part of a script writer, I don't always have control over preventing it from happening, if a script has a random GO statement at the beginning of the file (which SSMS doesn't complain about) then it tries to execute GO as a SQL Command.
i.e.
GO
SET ANSI_NULLS ON
GO
-- rest of script file
While there is no good reason to have an empty GO statement, it should be handled appropriately and not executed as a command statement.
By changing it to check for newline before or after, we can capture both start, end, and middle GO statements.
While it is bad practice on the part of a script writer, I don't always have control over preventing it from happening, if a script has a random GO statement at the beginning of the file (which SSMS doesn't complain about) then it tries to execute
GO
as a SQL Command. i.e.While there is no good reason to have an empty GO statement, it should be handled appropriately and not executed as a command statement.
By changing it to check for newline before or after, we can capture both start, end, and middle
GO
statements.This seems to work based on all my testing: