tags:

views:

103

answers:

5

I found something like this in a SqlServer DB stored proc:

SELECT stuff
  FROM mytable
 WHERE mytable.column = + @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.)

+4  A: 

+ is the opposite of - which changes sign.

It does nothing.

Quassnoi
if @paramater is an unsigned tinyint it would cast it to a smallint. I have the link from MS in my answer.
despart
+1  A: 

What type is @parameter? This probably just a unary plus, (as opposed to minus). For numeric types this has no effect.

recursive
It's a char(20)...but it is holding, in every case I can see, an integer value...so maybe it's just auto-casting it, and allowing the unary plus.
Beska
A: 

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.

Bob
A: 

Returns the data type of numeric_expression, except that an unsigned tinyint expression is promoted to a smallint result.

Positive unary operator

despart
+2  A: 

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.

geocar