Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

+ (Unary Plus) (Transact-SQL)

 

Applies To: SQL Server 2014, SQL Server 2016 Preview

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

Applies to: SQL Server (SQL Server 2008 through current version), Azure SQL Database.

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.

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)

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)

Community Additions

ADD
Show:
© 2015 Microsoft