Troubleshooting : Error – Incorrect syntax near ‘GO’
Posted by blakhani on August 28, 2014
Sometimes we are very comfortable and used to with certain things that if they change, we become nervous and uneasy. I have a lovely daughter and she always greets me when I come back home from office. That one “hello” takes away all my worries and I feel alive. Yesterday she didn’t do that and I was worried. I checked with my wife and she told that there was a mild fever and her mood is little different today. That made me little nervous.
Same feeling happened when I saw below in management studio of my colleague:
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ‘GO’.
and management studio intellisense feature was also complaining about syntax. “Incorrect syntax near ‘End Of File’. Expecting ‘=’. As per documentation “GO is not a Transact-SQL statement; it is a command recognized by the sqlcmd and osql utilities and SQL Server Management Studio Code editor”
I went to Tools > Option in Management studio and found that there was a customization done on batch separator. SSMS> Tools > Options >Query Execution > SQL Server > General > Batch Separator.
Which means if I run with “come” it should work and as expected.
Perfect! This mystery is solved now. This made me think that can we customize SQLCMD as well. If we look into help of SQLCMD we can see parameter -c cmdend
Here is the usage of parameter –c . I have used hello as command end parameter and hello works same as go in true sense.
I hope this clears some confusion about batch separator.
If you are getting this error while using ExecuteNonQuery in .net program and running script then refer http://blogs.msdn.com/b/onoj/archive/2008/02/26/incorrect-syntax-near-go-sqlcommand-executenonquery.aspx which has a workaround.
Hope this helps!
Aman said
Nice Tip and Tricks 🙂
blakhani said
Thanks @Aman