Home Blog SQL SQL script giving Incorrect syntax near ')'. 'END' error
SQL script giving Incorrect syntax near ')'. 'END' error
SQL
Written by Dicky   
Thursday, 03 March 2016 11:06
AddThis Social Bookmark Button

I created upgrade script for SQL project and often times, I get the following error:

Msg 102, Level 15, State 1, Line 80
Incorrect syntax near ')'.
Msg 102, Level 15, State 1, Line 82
Incorrect syntax near 'END'.

I have made sure the Execution Settings is at SQLCMD mode but it's still giving me that error. After digging deeper, it happens whenever I created a table e.g.,

IF OBJECT_ID(N'SomeTable', 'U') IS NULL
BEGIN
:r .\..\Tables\SomeTable.sql
END
GO

It turns out that SQLCMD doesn't like 'GO' keyword in between BEGIN and END so my solution is to move the table creation script and put it between BEGIN and END keyword and remove all the 'GO' keyword. You just need to have one 'GO' after the END. After that, my upgrade script file was parsed correctly. I wish Visual Studio would give a better error message.