• drew.allen (2/5/2016)


    Jacob Wilkins (2/4/2016)


    drew.allen (2/4/2016)


    Jacob Wilkins (2/4/2016)


    Unary plus and negative: https://msdn.microsoft.com/en-us/library/ms174362.aspx

    Cheers!

    EDIT: I must say that it is still strange that the unary plus works with string data, since the documentation specifies numeric data. However, it also basically says that it's a no-op, so maybe it's just ignored in that case. You do get an error if you try to use the unary minus with string data.

    On that note, that seems to be the one use for the unary plus, namely separating the unary minus so that they don't become comments. Of course, you might as well just use parentheses in that case, or just not apply two consecutive unary minus operators, since that doesn't exactly change much 🙂

    I assume that's because + can either be the arithmetic operator or string concatenation and the code to drop the unary + is processed before the need to identify whether it is behaving as the arithmetic or string operator.

    Drew

    I thought something like that at first, but doesn't explain why this works:

    SELECT +'What''s all this?'

    Cheers!

    Sure it does. The code is first parsed and then interpreted. The unary + is presumably dropped during parsing and then there is no need to interpret the string as numeric.

    Ah, I misread your post. That's as plausible an explanation as any; it would be nice if that behavior were fully documented, but it's not all that important 🙂

    Cheers!