• stewartc-708166 (3/28/2011)


    Hugo Kornelis (3/28/2011)


    I was surprised at first at the "SELECT @i+=1" syntax. I knew about the compount operators and have happily used "SET @i=1", but seeing never realised that it can equally well be used with SELECT.

    I have found the use of variable value allocation and updating using SELECT to be very efficient and handy.

    i.e., assigning or updating several variables using SET can only be assigned to 1 variable at a time, e.g.

    SET @Var1 += x

    SET @Var2 -= y

    SET @Var3 = ''

    while this could be effected in one instruction using the SELECT, e.g.

    SELECT @Var1 += x, @Var2 -= y, @Var3 = ''

    Thanks for the question. I have been coding on 2008 for awhile now and forgot that it would'nt work in prior versions. Regarding coding multiple assignments in one statement... I think it is easier to read multiple SET statements. But, to each her his/her own. I don't want to start a "religious war" over coding style. There's enough of that in the .NET forums. :w00t: