SQL Server ABS() Function

The ABS() function in SQL Server calculates the absolute value of a number. The absolute value is always non-negative (positive or zero), representing the magnitude of the number without considering its sign.



ABS(): Definition and Usage

ABS() is a very useful mathematical function. It's frequently used in situations where you only care about the magnitude of a number and not whether it's positive or negative. This is common in calculations involving distances, magnitudes, or other scenarios where the sign is irrelevant.

Syntax

Syntax

ABS(number)
      

Parameter Values

Parameter Description
number The number for which you want to compute the absolute value. This is required and must be a numeric value.

Example

Calculating the Absolute Value

This example shows how to use ABS() to obtain the absolute value of -243.5.

Syntax

SELECT Abs(-243.5) AS AbsNum;
      
Output

AbsNum
-------
243.5