Export (0) Print
Expand All

+ (Unary Plus) (Transact-SQL)

Returns the value of a numeric expression (a unary operator).

Topic link icon Transact-SQL Syntax Conventions

+ numeric_expression

numeric_expression

Is any valid expression of any one of the data types in the numeric data type category, except the datetime and smalldatetime data types.

Returns the data type of numeric_expression.

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.

A. Setting a variable to a positive value

The following example sets a variable to a positive value.

DECLARE @MyNumber decimal(10,2);
SET @MyNumber = +123.45;
SELECT @MyNumber;
GO

Here is the result set:

----------- 
123.45          

(1 row(s) affected)

B. Using the unary plus operator with a negative value

The following example shows using the unary plus with a negative expression and the ABS() function on the same negative expression. The unary plus does not affect the expression, but the ABS function returns the positive value of the expression.

USE tempdb;
GO
DECLARE @Num1 int;
SET @Num1 = -5;
SELECT +@Num1, ABS(@Num1);
GO

Here is the result set:

----------- -----------
-5          5

(1 row(s) affected)
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft