Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

- (Subtract) (Transact-SQL)

Subtracts two numbers (an arithmetic subtraction operator). Can also subtract a number, in days, from a date.

Topic link iconTransact-SQL Syntax Conventions

expression -expression


Is any valid expression of any one of the data types of the numeric data type category, except the bit data type. Cannot be used with date or time data types.

Returns the data type of the argument with the higher precedence. For more information, see Data Type Precedence (Transact-SQL).

A. Using subtraction in a SELECT statement

The following example calculates the difference in tax rate between the state or province with the highest tax rate and the state or province with the lowest tax rate.

USE AdventureWorks;
SELECT MAX(TaxRate) - MIN(TaxRate) AS 'Tax Rate Difference'
FROM Sales.SalesTaxRate

You can change the order of execution by using parentheses. Calculations inside parentheses are evaluated first. If parentheses are nested, the most deeply nested calculation has precedence.

B. Using date subtraction

The following example subtracts a number of days from a datetime date.

USE AdventureWorks;
DECLARE @altstartdate datetime;
SET @altstartdate = CONVERT(DATETIME, 'January 10, 1900 3:00 AM', 101);
SELECT @altstartdate - 1.5 AS 'Subtract Date';

Here is the result set:

Subtract Date


1900-01-08 15:00:00.000

(1 row(s) affected)

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft