Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » Math FunctionsRSS Feeds

ABS Function

Posted By: Vivek Patel     Category: SQL Server     Views: 8248

This article explains the use of ABS mathematical function in sql server with examples.

ABS function returns the absolute (positive) value of the specified numeric expression.

Syntax of ABS Function :

ABS ( numeric_expression)

Return type of ABS function is same type as numeric_expression.


Examples of ABS Function :

Example 1 : Passing Negative value to ABS Function

SELECT ABS(-23.43)

Output
23.43

Above example returns positive value of numeric expression. From above example -23.43 is converted to 23.43, ABS function has remove the negative portion of numeric_expression.


Example 2 : Passing Positive value to function to ABS Function 

SELECT ABS(15.38)

Output
15.38

In above example value passed was positive so it returned the same value as their no conversion require.


Example 3 : Use of ABS function to display positive part of table field. 

SELECT ABS(UnitsInStock)
FROM Products

Output
39
53
42
0
12

Above example displays positive part of field UnitsInStock of Products table.
  
Share: 

 
 
 

Didn't find what you were looking for? Find more on ABS Function Or get search suggestion and latest updates.

Vivek Patel
Vivek Patel author of ABS Function is from United States. Vivek Patel says

I have started working in .Net Technology since its beta release and lucky to got chance to work on .Net 1.1, 2.0 and now working on .Net 3.5. I have worked in both C# and VB.Net for Asp.net Projects. I can also provide Sharepoint development needs. I can efficiently switch role from Tech Lead and Developer. I have comprehensive knowledge of Asp.net Development. I have been award Microsoft Most Valuable Award twice in Asp.net Technology.

Blog: http://dotnetguts.blogspot.com

 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!