sql – Incorrect syntax near

sql – Incorrect syntax near

Such unexpected problems can appear when you copy the code from a web page or email and the text contains unprintable characters like individual CR or LF and non-breaking spaces.

Panagiotis Kanavos is right, sometimes copy and paste T-SQL can make appear unwanted characters…

I finally found a simple and fast way (only Notepad++ needed) to detect which character is wrong, without having to manually rewrite the whole statement: there is no need to save any file to disk.

Its pretty quick, in Notepad++:

  • Click New file
  • Check under the menu Encoding: the value should be Encode in UTF-8; set it if its not
  • Paste your text
    enter
  • From Encoding menu, now click Encode in ANSI and check again your text
    enter

You should easily find the wrong character(s)

sql – Incorrect syntax near

The error for me was that I read the SQL statement from a text file, and the text file was saved in the UTF-8 with BOM (byte order mark) format.

To solve this, I opened the file in Notepad++ and under Encoding, chose UTF-8. Alternatively you can remove the first three bytes of the file with a hex editor.

Leave a Reply

Your email address will not be published.