Returns the absolute value of a numeric expression.
ABS ( numeric_expression )
The numeric expression for which to return the absolute value.
Returns the same data type as numeric_expression
with the sign removed. Returns NULL if the input is NULL.
SELECT ABS(-123.45);
GO
This example returns the absolute value of a negative number.
Result:
123.45
SELECT ProductName, ABS(ListPrice - StandardCostPrice) AS PriceDifference
FROM Production.Product
WHERE ListPrice > StandardCostPrice;
GO
This example calculates the absolute difference between the list price and standard cost price for products where the list price is higher.
Sample Result:
ProductName | PriceDifference
-------------|-----------------
Adjustable Race| 5.74
Bearing | 1.25
Bottom Bracket| 15.99
The ABS
function can accept any data type from the numeric or binary data type categories, except for the xml
data type.
If the value of numeric_expression
is a binary data type, the ABS
function returns the absolute value of the number that is represented by the binary expression.
SQL Server 2022 (16.x), SQL Server 2019 (15.x), SQL Server 2017 (14.x), SQL Server 2016 (13.x), SQL Server 2014 (12.x), SQL Server 2012 (11.x), Azure SQL Database, Azure Synapse Analytics, Parallel Data Warehouse.