ABS

Returns the absolute value of a numeric expression.

Syntax

ABS ( numeric_expression )

Parameters

numeric_expression: Is an expression of the exact numeric, approximate numeric, or binary data type category.

The numeric expression for which to return the absolute value.

Return Type

Returns

Returns the same data type as numeric_expression with the sign removed. Returns NULL if the input is NULL.

Examples

Example 1: Simple usage

SELECT ABS(-123.45);
GO

This example returns the absolute value of a negative number.

Result:

123.45

Example 2: Using with a table column

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

Remarks

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.

Applies to

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.