Tutorialsteacher

Follow Us

SQL Server ABS() Function

SQL Server ABS() function is a mathematical function that returns the absolute(positive) value of a given numeric expression.

The ABS() function changes negative values to positive values. It has no effect on zero or positive values.

ABS(numeric_expression)

Parameters

numeric_expression: The specified numeric value whose absolute value is returned by ABS() function.

Note: numeric_expression is of numeric data type or of any non-numeric data type that can be implicitly converted to a numeric value.

Return Value

Returns the absolute value of the specified numeric value.

The return type will be the same data type as the input value.

Example 1:

The following example shows the use of the ABS() function:

Example: ABS()
SELECT ABS (-1.0) AS NegResult, 
    ABS(1) AS PosResult, ABS (0) AS ZeroResult

Example 2:

The ABS() can return the absolute value of expressions as shown in the following example

Example: ABS()
SELECT ABS(-7 + 5) AS Result