Synopsis
Returns the absolute (positive) value of the numeric expression.
Syntax
Parameters
Return Value
ABS ( numeric_expression )
| numeric_expression | Expression of any numeric data type. The argument can be a tinyint, smallint, int, bigint, decimal, numeric, float, or real value. |
|---|
The return type is the same as the input type, except for float and real, which return float.
Examples
Basic Usage
Using with Columns
SELECT ABS(-5) AS AbsValue1,
ABS(5.23) AS AbsValue2;
Result:
AbsValue1 AbsValue2
---------- ----------
5 5.23
CREATE TABLE SalesAmount
(
SaleId int,
Amount decimal(10,2)
);
INSERT INTO SalesAmount VALUES
(1, 150.00),
(2, -200.50),
(3, 75.25);
SELECT SaleId,
Amount,
ABS(Amount) AS AbsoluteAmount
FROM SalesAmount;
Result:
SaleId Amount AbsoluteAmount
------ -------- ---------------
1 150.00 150.00
2 -200.50 200.50
3 75.25 75.25