• Adi Cohn-120898 (7/8/2013)


    Hi all

    Pleas check out the code bellow:

    declare @tbl table (i int)

    declare @i int

    insert into @tbl (i) values (1)

    update @tbl

    set @i = i, i = 2

    select @i as varible, i from @tbl

    This code stores the column's old value in a variable and then modifies the column's value. I know that code like that has been working for years, but I don't know if it is something that could be modified in the future. If an application has this kind of code, could it break with the next service pack or next SQL Server version or is this kind of code something that should always work?

    Adi

    It sounds like you're scoping out a project, Adi. What do you actually need this for? I ask because what you've posted makes up the "guts" of what has become endearingly known as the "Quirky Update" which, BTW, can also take the form of SET @variable = column = expression when used with some care.

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