One of our application devs came to me with an interesting question. In the following code, you'll see that the update statement is assigning the current column values to two variables, but also updating those same columns to new values.
The question was, is it guaranteed that the variables @oStart and @oFinish will be assigned to the old values of [Start] and [Finish] and not the new values? Under testing, this has been the case, however, I'd like to confirm this is the guaranteed behaviour.
I expect the answer is "no - it's not guaranteed", and ultimately, it's down to the decision the optimiser takes. Regardless, this kind of ambiguous code is to be discouraged anyway (there are more elegant and readable ways of writing it), but would be interested to hear everyone's thoughts.
-- Parameters DECLARE @StartDate smalldatetime = '2022-01-01', @EndDate smalldatetime = '2022-12-31'; -- Body DECLARE @oStart smalldatetime, @oFinish smalldatetime; UPDATE [dbo].[MyTable] SET @oStart = [Start], @oFinish = [Finish], [Start] = @StartDate, [Finish] = @EndDate WHERE [ID] = 12;