ABS
Description
The ABS function is used to calculate the absolute value of a given numerical expression. Whether the input value is positive or negative, the ABS function can return the corresponding non-negative value.
Syntax
Parameters
expr: A numeric expression for which the absolute value needs to be calculated. It can besmallint,tinyint,int,bigint,decimal,double, orfloat.
Return Value
Returns the absolute value of the parameter expr. The return type is the same as the input parameter type.
Example Usage
- Calculate the absolute value of a negative integer:
- Calculate the absolute value of a positive integer:
- Calculate the absolute value of a decimal:
- Calculate the absolute value of a negative number with a decimal point:
- Calculate the absolute value of a
decimaltype:
- Use the
ABSfunction in a query to get the absolute value of employee salaries:
Notes
- When
exprisNULL, theABSfunction will returnNULL. - The
ABSfunction can be used in conjunction with other SQL functions, such as when sorting or filtering queries.
