2

Getting error in SQL Server

Incorrect syntax near "GO"

when I copy page script from notepad.

But if I write "GO" instead of copy paste in SQL Server Management Studio then I don't get that error

enter image description here

enter image description here

Notepad file: download file

Ali
  • 3,545
  • 11
  • 44
  • 63
  • If you delete between `Northwind` and `GO` then hit enter and run again, does it work? If you copy the working query from SSMS to notepad then back again, does it work? – Hart CO Apr 27 '15 at 16:16
  • If I remove first GO (line # 2) then same error. If I remove second GO (line # 4) then it works. I guess there is some kind of encoding problem – Ali Apr 27 '15 at 16:20
  • I've seen such things in imported files before, but never in copied queries, but you can change the encoding of your notepad file, or use a different text editor altogether. – Hart CO Apr 27 '15 at 16:25
  • I coped four lines into notepad file and saved and closed.Then I opened it and copied pasted to sqlserver management studio. Same error. I am going to attach notepad file here (that I tested). Someone give me script file which have more then 10,000 rows. So I don't want to replace go or something like that – Ali Apr 27 '15 at 16:26
  • *someone give me notepad file(txt file) of queries (not database script file) – Ali Apr 27 '15 at 16:32
  • I have changed encoding of notepad file but still not working. – Ali Apr 27 '15 at 16:40
  • 4
    I bet if you opened this in a hex editor you'd see there is some hidden character on the line. – dmeglio Apr 27 '15 at 17:12
  • What if you manually type the lines into a new blank file in Notepad, and then copy them to SSMS and execute them? – Tab Alleman Apr 27 '15 at 18:39
  • 1
    I get same error message from your file (even if I replace Northwind with one of my own databases). In hex edit, the only difference I can see is the first statement has a CrLf before `GO` while the second has a Cr. This cannot cause the failure, and replacing the Cr with CrLf still causes the error. Flabbergasted – HoneyBadger Apr 28 '15 at 08:00

1 Answers1

0

As I said in a comment: the only difference is a Cr vs CrLf. I didn't expect it to make a difference, nor have I ever seen it make a difference. Queries with Cr or Lf or CrLf have always worked perfectly fine for me. However, apparently, the sql parser sometimes does have a problem with Cr. (Based on the answers to this question). So I guess a replace is what you need to do, unpleasant as it is.

Community
  • 1
  • 1
HoneyBadger
  • 14,750
  • 3
  • 34
  • 48