Incorrect syntax near 'go' in SQL Server Management Studio

SQL Server Management Studio can't handle some non printable characters.

Check the newline characters, probably you have Linux (LF) or Mac style (CR) instead of Windows style (CR and LF). You can check with any advanced text editor, for example Notepad++·


Been suffering with this problem mightily. Finally, used Notepad++.

Fixed by:

Format>Convert to UNIX

followed by

Format>Convert to Windows


You opened a file in Mac format, with Carriage Returns ('\r') newlines.

The SQL parser behaves inconsistently on CR newlines. It supports them for some queries, like "select 1 go", but fails on others, like "drop function f go".

Convert all your sql files to windows encoding.