Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate A Temp Table
    primarykey
    data
    text
    <p>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. </p> <p>I'm able to insert the Dates through 2099, "N" in BankHoliday and "Null" in <code>HolidayName</code> 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...</p> <pre><code>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 ) &lt; @LastDate begin Set @WorkingDate = DATEADD (day,1,(select MAX(DATE) from #CACFederalReserverHolidays)) if @WorkingDate &lt;= @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  </code></pre>
    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.
 

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