Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think that you may have found an actual bug in SQL Server (or in Management Studio).</p> <p>These two UPDATE statements:</p> <pre><code>update #CACFederalReserverHolidays  set BankHoliday = 'Y',   HolidayName = 'New Year''s Day'   where DATEPART(day,Date) = 1   and DATEPART(month,Date) = 1   and DATEPART(Dw,Date) between 2 and 6   update #CACFederalReserverHolidays    set BankHoliday = 'Y',   HolidayName = 'New Year''s Day'   where DATEPART(day,Date) = 1   and DATEPART(month,Date) = 1   and DATEPART(Dw,Date) = 2 </code></pre> <p>Appear to have some kind of invalid space characters and/or line breaks within the first two lines. However, when I scan it one character at a time, I can not find any Unicode values that should cause this. Nonetheless, when I edit out all of the spaces and line-breaks and then re-enter them by hand, the queries no longer get "Invalid Syntax" errors.</p> <p>I suggest that you do the same thing. But first, I would request that you copy these lines and take them to Microsoft Connect and enter them as a possible bug.</p> <p>(Actually, I'll be happy to enter this into MS Connect, if you want.)</p> <hr> <p>I have entered this into Microsoft Connect as a SQL Server bug here: <a href="https://connect.microsoft.com/SQLServer/feedback/details/775641/ssms-throws-spurious-incorrect-syntax-error" rel="nofollow noreferrer">https://connect.microsoft.com/SQLServer/feedback/details/775641/ssms-throws-spurious-incorrect-syntax-error</a>. Feel free to go there and upvote or comment on it and/or indicate if you can reproduce it yourself.</p> <hr> <p>I just figured it out. Here is my revised posting for Connect, which explains it pretty well:</p> <blockquote> <p>When I execute the following text verbatim in SSMS:</p> <pre><code>update #CACFederalReserverHolidays  set BankHoliday = 0 </code></pre> <p>It throws the error "Incorrect syntax near ' '." As far as I can tell it should just say that the #temp table is undefined. Note: Even if the #temp table is defined, it throws the same error.</p> <p>I got this from a user's question on a support forum (here: <a href="https://stackoverflow.com/questions/14129706/update-a-temp-table/14130003#14130003">Update A Temp Table</a>). Cutting and pasting the user's text into my SSMS, I was able to narrow it down to these two lines. After a lot of editing and testing, I found that the problem would only go away if I removed the line-break and spaces between the first and second line and then re-entered them myself. Suspecting some invisible/invalid character, I then quoted the text and examined it character by character with:</p> <pre><code>select unicode(substring('update #CACFederalReserverHolidays  set BankHolidayX = 0', 35,1)) </code></pre> <p>But looking at characters 35, 36, and 37, only revealed the Unicode values 13, 10, and 63 (CR, LF and Space).</p> <p>As far as I can tell, this must be a bug, either in Management Studio, or in the SQL Server Parser itself.</p> <p>Note that I have only reproduced this on SQL Server 2012 so far, but the original user reported it from SQL Server 2008.</p> <hr> <p>OK, I have just realized that my examination procedure above was flawed because I was converting it to ASCII before looking at the Unicode values. When I use the correct expression:</p> <pre><code>select unicode(substring(N'update #CACFederalReserverHolidays  set BankHolidayX = 0', 37,1)) </code></pre> <p>It reveals that character 37 is actually Unicode value 8200. I am unfamiliar with this but I assume that it is invalid.</p> </blockquote> <hr> <p>So long story short, it appears that some of the spaces in the SQL code (specifically the spaces in front of the <code>set ..</code> lines after the <code>update..</code> are not true spaces (Unicode 63), but are actually Unicode character 8200 ("PUNCTUATION SPACE", U+2008). Obviously you'll need to replace these with spaces.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload