- (Negative) (Transact-SQL)
Collapse the table of content
Expand the table of content

- (Negative) (Transact-SQL)

 

THIS TOPIC APPLIES TO: yesSQL Server (starting with 2008)yesAzure SQL DatabaseyesAzure SQL Data Warehouse yesParallel Data Warehouse

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

Topic link icon Transact-SQL Syntax Conventions

  
- numeric_expression  

-- Azure SQL Data Warehouse and Parallel Data Warehouse  
      -   
      numeric_expression  
  

numeric_expression
Is any valid expression of any one of the data types of the numeric data type category, except the date and time category.

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

A. Setting a variable to a negative value

The following example sets a variable to a negative value.

USE tempdb;  
GO  
DECLARE @MyNumber decimal(10,2);  
SET @MyNumber = -123.45;  
SELECT @MyNumber AS NegativeValue;  
GO  

Here is the result set.

NegativeValue  
---------------------------------------  
-123.45  
  
(1 row(s) affected)  
  

B. Changing a variable to a negative value

The following example changes a variable to a negative value.

USE tempdb;  
GO  
DECLARE @Num1 int;  
SET @Num1 = 5;  
SELECT @Num1 AS VariableValue, -@Num1 AS NegativeValue;  
GO  
  

Here is the result set.

VariableValue NegativeValue  
------------- -------------  
5             -5  
  
(1 row(s) affected)  
  

C. Returning the negative of a positive constant

The following example returns the negative of a positive constant.

USE ssawPDW;  
  
SELECT TOP (1) - 17 FROM DimEmployee;  

Returns

-17  

D. Returning the positive of a negative constant

The following example returns the positive of a negative constant.

USE ssawPDW;  
  
SELECT TOP (1) – ( - 17) FROM DimEmployee;  

Returns

17  

E. Returning the negative of a column

The following example returns the negative of the BaseRate value for each employee in the dimEmployee table.

USE ssawPDW;  
  
SELECT - BaseRate FROM DimEmployee;  

Data Types (Transact-SQL)
Expressions (Transact-SQL)
Operators (Transact-SQL)

Community Additions

ADD
Show:
© 2016 Microsoft