ABS function returns the absolute (positive) value of the specified numeric expression.
Syntax of ABS Function :
ABS ( numeric_expression)
Return type of ABS function is same type as numeric_expression.
Examples of ABS Function :
Example 1 : Passing Negative value to ABS Function
SELECT ABS(-23.43)
Output
23.43
Above example returns positive value of numeric expression. From above example -23.43 is converted to 23.43, ABS function has remove the negative portion of numeric_expression.
Example 2 : Passing Positive value to function to ABS Function
SELECT ABS(15.38)
Output
15.38
In above example value passed was positive so it returned the same value as their no conversion require.
Example 3 : Use of ABS function to display positive part of table field.
SELECT ABS(UnitsInStock)
FROM Products
Output
39
53
42
0
12
Above example displays positive part of field UnitsInStock of Products table.