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

- (Negative) (Transact-SQL)

Applies To: SQL Server 2014, SQL Server 2016 Preview

Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).

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

Applies to: SQL Server (SQL Server 2008 through current version), Azure SQL Database, Azure SQL Data Warehouse Public Preview.

Topic link icon Transact-SQL Syntax Conventions

- 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)

Community Additions

ADD
Show:
© 2015 Microsoft