What does =+ mean in (T)SQL?
I found something like this in a SqlServer DB stored proc:
SELECT stuff
FROM mytable
WHERE mytable.column = + @开发者_StackOverflow社区parameter
It seems to run without error, so I assume it's okay. What would the "+" be doing?
(Not surprisingly, this is a difficult topic to effectively search on, so I apologize in advance if this is a duplicate.)
+
is the opposite of -
which changes sign.
It does nothing.
Unary +
doesn't do anything in T-SQL.
Perhaps the person who wrote it saw 0+@parameter
and deleted the 0
to "optimize it". 0+@parameter
generates an error if @parameter
isn't numeric, whereas unary +
doesn't do anything.
What type is @parameter
? This probably just a unary plus, (as opposed to minus). For numeric types this has no effect.
Returns the data type of numeric_expression, except that an unsigned tinyint expression is promoted to a smallint result.
Positive unary operator
It looks like it is a short hand notation for converting the parameter into a numeric type. Depending on your database server, it might not even be needed.
精彩评论