• Hugo Kornelis (10/29/2010)


    da-zero (10/29/2010)


    Hardy21 (10/29/2010)


    Thanks for the link. Hence, @a =+ @b-2 means @b-2 value assign to @a so @a = -21.

    Indeed. But why doesn't SQL Server give a syntax error? I would've liked that in the explanation.

    Becuase there is no invalid syntax. Spaces are (mostly) ignored by SQL Server, so @a =+ @b-2 is equivalent to @a=+@b, or to @a = +@b. The latter alternative is the most human-comprehensible. @a is assigned the result of applying the unqry + operator on @B. (And since the unary + operator is basically a no-op, you simply assign @a the value of @b-2).

    Great. Thanks for the explanation! Now it seems really simple. 🙂

    (I was waiting until you would post on this thread and take all doubt away :-D)

    edit: your explanation comfirms my initial statement that the explanation of the questions' poster is incorrect, as it has nothing to do with pre-increment operators, but with misplacing the + so that SQL Server ignores the unary operator. Maybe the question would have been more difficult (or tricky) if it contained =-

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP