The Triple Update

  • Jeff Moden wrote:

    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.

  • Magnus Ahlkvist wrote:

    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


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Rune Bivrin wrote:

    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.

     

  • 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