you're reading...
SQL Server, T-SQL

Incorrect syntax near “GO”

SQL Error (102): Incorrect syntax near “GO”




I recently wrote some code to generate CRUD procedures for a Data Warehouse project and I was receiving an error message on the batch T-SQL “GO” statement when executing the sql code that was generated ? 

Msg 102, Level 15, State 1, Procedure, Line 1
Incorrect syntax near ‘GO’.

When I looked at the generated sql output I could not see any issues syntactically??? I beat my head against the wall reviewing the code for about an hour trying to figure out why it would not run. The only thing that I saw was that I was using the “+ char(13)” line feed in the dynamic sql script generation. Out of pure frustration I decided to wrap the “GO” statements in a  CRLF or CHAR(13) + CHAR(10). Lo and behold the batched create procedure statements ran without issue or so it seemed. I was still getting intermittent issues with the “GO” statements . I then checked my SSMS query settings for the batch separator and it was set to “GO”. I decided to take another look at the code itself and I noticed I had set the variable holding the actual SQL statements to NVARCHAR(MAX). I thought to myself could this be a contributing factor? I guess it could allow for non printable characters. I changed any occurance of any variable that was used to hold any sql code VARCHAR and the “GO” statements ran without issue. This is the first time I have encountered this issue maybe it has something to do with SSMS 2012? In any case if you encounter something similar maybe this post will help.

Bon Appetite…



About ldgaller

Accomplished Data Warehouse Architect, DBA and Software Architect with over 15 years of professional experience and demonstrated success designing and implementing solutions that improve business functionality and productivity. Highly diverse technical background with proven ability to design, develop and implement technology on an enterprise level. I approach all projects with passion, diligence, integrity, and exceptional aptitude.


No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: