What does a plus sign in a SQL WHERE clause (WHERE + userName = SYSTEM_USER)

前端 未结 2 2084
鱼传尺愫
鱼传尺愫 2021-01-14 09:12

I am stuck on trying to find the meaning of a plus sign in a where clause. Anyone have any ideas on this one? Been stuck for a bit on it. The query itself is pretty simple a

相关标签:
2条回答
  • 2021-01-14 09:15

    It looks like the plus operator in the where clause is used for left or right outer joins.

    You don't need it in your case, but you can read up on them here.

    The reason your query works the same either way is because data is only coming from a single table. The join is superfluous.

    A quick search also lead me to this answer, which states using the + method for joins is not recommended.

    Update

    Since you're using Microsoft SQL Server 2008, this is my best guess:

    The '+' operator is used for string concatenation.

    0 讨论(0)
  • 2021-01-14 09:31

    The unary + operator is simply a no op. This is explained in the documentation for this operator, which is here:

    Although a unary plus can appear before any numeric expression, it performs no operation on the value returned from the expression. Specifically, it will not return the positive value of a negative expression. To return positive value of a negative expression, use the ABS function.

    I actually believe this remark is a wee little bit misleading. I think the unary plus operator will convert a string argument to a number. When applied to a constant string filled with digits, this could actually be beneficial as a way of encouraging the compiler to use an index on a numeric field.

    0 讨论(0)
提交回复
热议问题