| title | - (Subtraction) (Transact-SQL) | ||||
|---|---|---|---|---|---|
| description | Subtract two numbers using this built-in arithmetic subtraction operator. | ||||
| author | rwestMSFT | ||||
| ms.author | randolphwest | ||||
| ms.date | 07/15/2025 | ||||
| ms.service | sql | ||||
| ms.subservice | t-sql | ||||
| ms.topic | reference | ||||
| ms.custom |
|
||||
| f1_keywords |
|
||||
| helpviewer_keywords |
|
||||
| dev_langs |
|
||||
| monikerRange | >=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric || =fabric-sqldb |
[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw-fabricsqldb]
Subtracts two numbers (an arithmetic subtraction operator). Can also subtract a number, in days, from a date.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
expression - expression
Any valid expression of any one of the data types of the numeric data type category, except the bit data type. Can't be used with date, time, datetime2, or datetimeoffset data types.
Returns the data type of the argument with the higher precedence. For more information, see Data type precedence.
[!INCLUDE article-uses-adventureworks]
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.
Applies to: [!INCLUDE ssNoVersion] and [!INCLUDE ssSDS].
SELECT MAX(TaxRate) - MIN(TaxRate) AS 'Tax Rate Difference'
FROM Sales.SalesTaxRate
WHERE StateProvinceID IS NOT NULL;
GOYou 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.
The following example subtracts several days from a datetime date.
Applies to: [!INCLUDE ssNoVersion] and [!INCLUDE ssSDS].
DECLARE @altstartdate DATETIME;
SET @altstartdate = CONVERT(DATETIME, 'January 10, 1900 3:00 AM', 101);
SELECT @altstartdate - 1.5 AS 'Subtract Date';[!INCLUDE ssresult-md]
Subtract Date
-----------------------
1900-01-08 15:00:00.000
The following example calculates the difference in a base rate between the employee with the highest base rate and the employee with the lowest tax rate, from the dimEmployee table.
SELECT MAX(BaseRate) - MIN(BaseRate) AS BaseRateDifference
FROM DimEmployee;