I am going to start a series of short articles or tidbits on Transaction SQL math functions. Most, if not all, of these functions have been in the product before the release of SQL Server 2005.
I am very proud of my daughter making the advance math class in sixth grade. I am dedicating these blogs to her hard class work and love of the subject.
I will be exploring the absolute values, ABS() function today. This function takes a expression in either exact numeric or approximate numeric form and returns the positive value.
The example below tests the ABS() function with three different inputs: negative numbers, positive numbers and a null value.
1 2 3 4 5 6 7 8 9 10 |
-- -- Absolute value (ABS) Function -- -- Absolute value of number (remove sign) SELECT ABS(-10) AS NEGATIVE, ABS(10) AS POSITVE, ABS(NULL) as UNKNOWN; GO |
The output from the test is listed below.
1 2 3 4 5 |
output: NEGATIVE POSITVE UNKNOWN ---------- ---------- ---------- 10 10 NULL |
In a nutshell, this function will return the positive value of any numeric expression.