Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9080933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:11:34+00:00 2026-06-16T20:11:34+00:00

I’m working on creating some reporting for the new year. I lifted this code

  • 0

I’m working on creating some reporting for the new year. I lifted this code and attempted to make it work for a temp table as I don’t have create table rights on my DB. I commented out the PKey portion as I didn’t think I needed it in a temp table.

I’m able to insert the Dates through 2099, “N” in BankHoliday and “Null” in HolidayName columns in the temp table. But, when I go to run the update portion for “New Years Day” holiday separately or as one long query I get the same syntax error. “Incorrect syntax near ‘ ‘.” Just when I think I know what I’m doing too…

Declare @FirstDate as Date
Declare @LastDate as Date
Declare @WorkingDate as Date

set @FirstDate = '01-01-2010'
SET @LastDate = '12-31-2099'

-- create holiday table replace # with dbo for permanent table
begin
create table #CACFederalReserverHolidays
(
[Date] Date Not Null,
BankHoliday nvarchar(1) Null,
HolidayName nvarchar(50) Null,
) ON [Primary]
end

----add primary key replace # with dbo for permanent table

--begin
--alter table #CACFederalReserverHolidays add constraint
--PK_CACFederalReserverHolidays Primary Key Clustered
--(
--Date
--)
--With (Statistics_NoRecompute = off,
--  Ignore_Dup_Key = Off,
--  Allow_Row_Locks = On,
--  Allow_Page_Locks = On) On [Primary]
--end

-- insert the first date

Insert into #CACFederalReserverHolidays 
([Date],[BankHoliday])
Values
(@FirstDate,'N')

-- insert the remaining dates by adding 1 to the last date
While (select MAX(DATE)
from #CACFederalReserverHolidays
) < @LastDate

begin
Set @WorkingDate =  DATEADD (day,1,(select MAX(DATE) from #CACFederalReserverHolidays))
if @WorkingDate <= @LastDate
    begin
        insert into #CACFederalReserverHolidays
        ([Date], [BankHoliday])
        Values
        (@WorkingDate, 'N')
            end
    else
        break
end

--ID Fed Holidays
begin
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
end

begin 
-- MLK Day, 3rd Mon in January
update #CACFederalReserverHolidays
 set BankHoliday = 'Y', 
    HolidayName = 'Martin Luther King Day'
    where DATEPART(day,Date) between 15 and 21
    and DATEPART(month,Date) = 1
    and DATEPART(Dw,Date) = 2
end     
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:11:35+00:00Added an answer on June 16, 2026 at 8:11 pm

    I think that you may have found an actual bug in SQL Server (or in Management Studio).

    These two UPDATE statements:

    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
    

    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.

    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.

    (Actually, I’ll be happy to enter this into MS Connect, if you want.)


    I have entered this into Microsoft Connect as a SQL Server bug here: https://connect.microsoft.com/SQLServer/feedback/details/775641/ssms-throws-spurious-incorrect-syntax-error. Feel free to go there and upvote or comment on it and/or indicate if you can reproduce it yourself.


    I just figured it out. Here is my revised posting for Connect, which explains it pretty well:

    When I execute the following text verbatim in SSMS:

    update #CACFederalReserverHolidays
     set BankHoliday = 0
    

    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.

    I got this from a user’s question on a support forum (here:
    Update A Temp Table).
    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:

    select unicode(substring('update #CACFederalReserverHolidays
     set BankHolidayX = 0', 35,1))
    

    But looking at characters 35, 36, and 37, only revealed the Unicode
    values 13, 10, and 63 (CR, LF and Space).

    As far as I can tell, this must be a bug, either in Management Studio,
    or in the SQL Server Parser itself.

    Note that I have only reproduced this on SQL Server 2012 so far, but
    the original user reported it from SQL Server 2008.


    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:

    select unicode(substring(N'update #CACFederalReserverHolidays
     set BankHolidayX = 0', 37,1))
    

    It reveals that character 37 is actually Unicode value 8200. I am
    unfamiliar with this but I assume that it is invalid.


    So long story short, it appears that some of the spaces in the SQL code (specifically the spaces in front of the set .. lines after the update.. 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.