Open In App

ABS() Function in SQL Server

Improve
Improve
Like Article
Like
Save
Share
Report

ABS() function :

This function in SQL Server is used to return the absolute value of a specified number. Absolute value is used for depicting the distance of a number on the number line from 0. The direction of the number from zero is not considered since the absolute value of a number is never negative. This function takes as an argument any numeric data type or any non-numeric data type that can be implicitly converted to a numeric data type. The value returned by this function is of the same data type as the numeric data type of the argument.

Features :

  • This function is used to find the absolute value of a specified number.
  • This function accepts a single parameter.
  • The accepted parameter is of numeric data type or any non-numeric data type that can be implicitly converted to a numeric data type.
  • The returned value will be in the same data type as the numeric data type of the specified parameter.

Syntax :

SELECT ABS(number);

Parameter :

This method accepts a parameter as given below:

  • number: Specified numeric value whose absolute value going to be returned.

Returns :

It returns the absolute value of a specified number.

Example-1 :

Getting the absolute value 0 of a specified number 0.

SELECT ABS(0);

Output :

0

Example-2 :

Getting the absolute value .7 of a specified number -0.7

SELECT ABS(-0.7);

Output :

.7

Example-3 :

Using ABS() function with a variable and getting the absolute value 123 of a specified number 123.

DECLARE @Parameter_Value INT;
SET @Parameter_Value = 123;
SELECT ABS(@Parameter_Value);

Output :

123

Example-4 :

Using ABS() function with a variable and getting the absolute value 34.87 of a specified float value “-34.87”.

DECLARE @Parameter_Value float;
SET @Parameter_Value = -34.87;
SELECT ABS(@Parameter_Value);

Output :

34.869999999999997

Application :

This function is used to return the absolute value of a specified numeric value.


Last Updated : 29 Dec, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads