This should be a simple UPDATE, which in my opinion should update the same record twice on two different columns, but it doesn't work.
A simplified sample code:
DECLARE @nowWithDate DATETIME = GETDATE() DECLARE @result TABLE(Id INT, Poll1Date DATETIME, Poll2Date DATETIME) INSERT INTO @result VALUES(1, NULL, NULL) ;WITH data(Id, IsPoll1, IsPoll2) AS ( SELECT 1, 1, 0 UNION ALL SELECT 1, 0, 1 ) UPDATE r SET Poll1Date = IIF(d.IsPoll1 = 1, @nowWithDate, Poll1Date), Poll2Date = IIF(d.IsPoll2 = 1, @nowWithDate, Poll2Date) FROM @result r JOIN data d ON d.Id = r.Id SELECT * FROM @result I can't figure it out, why the second date not updated? It looks like this row is updated only once.
why the second date is not provided?... what does this mean?datathat match the ID@result, and you're updating both columns in@resulteach time. Whichever row it processes second overwrites the values updated from the first update, no? Sounds like you need to group on the ID in your update statement and use MAX on theIsPollcolumns.