March 12, 2020 at 11:38 am
call.copse wrote:Jeff Moden wrote:...
Heh... I wonder how many people actually got this question right without having to run the code?
Even I knew about quirky update and I'm only a lowly developer. Surprised Steve wasn't familiar, guess it's a bit niche.
You, good Sir, are neither "only" nor "lowly". 😀
Jeff Moden has noticed me! Sorry, I'm not some kind of fanboi but that has made my (extremely unpleasant otherwise) day.
March 12, 2020 at 9:54 pm
This is fun code to test and try to get ones head around - in which orders are operators applied.
DECLARE @i INT=0;
UPDATE t SET @i = id = @i + 1
SELECT @i;
Just be careful with that. It's not guaranteed to work in the proper order without following some pretty strict rules.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 12, 2020 at 11:14 pm
Interesting, but I'd be wary of using it. In a multi-row update, the result is pretty much undefined, unless all the rows are updated to the same value. And in that case, there isn't much point in the approach anyway, unless you really want to confuse the reader...
I have used this to capture intermediate calculations that were used in subsequent calculations in the same row of data. I wish I could find the thread here on SSC that I did this to help on OP, but it was so long ago.
November 4, 2020 at 7:05 pm
That was interesting!
/Håkan Winther
MCITP:Database Developer 2008
MCTS: SQL Server 2008, Implementation and Maintenance
MCSE: Data Platform
Viewing 4 posts - 16 through 18 (of 18 total)
You must be logged in to reply to this topic. Login to reply