+ (Unary Plus) (Transact-SQL)

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

Topic link iconTransact-SQL Syntax Conventions

Syntax

+ numeric_expression

Arguments

  • 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.

Result Types

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

Remarks

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.

Examples

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)