开发者

What does =+ mean in (T)SQL?

开发者 https://www.devze.com 2022-12-10 07:23 出处:网络
I found something like this in a SqlServer DB stored proc: SELECT stuff FROM mytable WHERE mytable.column = + @开发者_StackOverflow社区parameter

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号