Sql updating table from temp table


29-Oct-2019 19:35

I want to append the the results from the second insert to the first insert and have one solid table.

EDIT: I think I found the solution: INSERT INTO #Temp Table (ID, CId, Tag Id, Beginning_X, Beginning_Y) SELECT ID, CId, Tag Id, X, Y from Table_1 WHERE Is Repeat = 1 UNION SELECT Convert(Null, int) AS ID, Convert(Null, tinyint) AS CId, Convert(Null, int) AS Tag Id, X, Y FROM Table_1 t WHERE t.

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).

After each exercise, we provide the solution so you can check your answer.

If IGNORE is provided, all errors encountered during the update are ignored.

Declare @First Date as Date Declare @Last Date as Date Declare @Working Date as Date set @First Date = '' SET @Last Date = '' -- create holiday table replace # with dbo for permanent table begin create table #CACFederal Reserver Holidays ( [Date] Date Not Null, Bank Holiday nvarchar(1) Null, Holiday Name nvarchar(50) Null, ) ON [Primary] end ----add primary key replace # with dbo for permanent table --begin --alter table #CACFederal Reserver Holidays add constraint --PK_CACFederal Reserver Holidays Primary Key Clustered --( --Date --) --With (Statistics_No Recompute = off, -- Ignore_Dup_Key = Off, -- Allow_Row_Locks = On, -- Allow_Page_Locks = On) On [Primary] --end -- insert the first date Insert into #CACFederal Reserver Holidays ([Date],[Bank Holiday]) Values (@First Date,'N') -- insert the remaining dates by adding 1 to the last date While (select MAX(DATE) from #CACFederal Reserver Holidays ) update #CACFederal Reserver Holidays set Bank Holiday = 'Y', Holiday Name = 'New Year''s Day' where DATEPART(day, Date) = 1 and DATEPART(month, Date) = 1 and DATEPART(Dw, Date) between 2 and 6 update #CACFederal Reserver Holidays set Bank Holiday = 'Y', Holiday Name = '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.

"Incorrect syntax near ' '." Just when I think I know what I'm doing too...

On the rare occurrence that I do see them indexed, it’s a nonclustered index on a column or two.