Friday, April 21, 2017

ABS() in SQL Server


SQL ABS() function is used to return the absolute value of the numeric expression. Absolute value is positive value, ABS() changes the negative values into positive values. It does not have any effect on zero (0) or positive value, they remain unchanged. NULL values are not considered. ABS() does not work on non-numeric columns such as text.


Syntax:

     
            SELECT ABS (numeric_expression)


numeric_expression is the numeric value of which absolute value is to be calculated.


Example 1:
ABS() on numeric column.

SELECT * FROM TempEmployeePayHistory




SELECT Rate, ABS(Rate) FROM TempEmployeePayHistory




Example 2:
ABS() on column with NULL values.

          SELECT * FROM TempEmployeePayHistory




SELECT Rate, ABS(Rate) FROM TempEmployeePayHistory




Example 3:
ABS() on text column.

          SELECT * FROM DatabaseLog




          SELECT [Event], ABS([Event]) FROM DatabaseLog




Share This
Previous Post
Next Post

TekGrabs, established in 2017, is in the business of sharing Information. It provides news, articles and photos about the different technologies, inventions in different domains. Provides information on programming and databases.

0 comments: