SQL Server Mathematical Functions – Free Tutorial and Online Training

In SQL Server, there are a lot of library functions. This article describes the use of several Mathematical functions with examples.

  1.     SQRT():

SQRT () function is commonly used in SQL and takes numeric value & gives square root of that number as output

Example:
Query:  Select SQRT (100);
Result:  10  

Query:  Select SQRT (169);
Result:  13  


  1.     PI():

PI() is used to get the value of PI in mathematics.

Example:
Query:  Select PI ();
Result:  3,14159265358979  

Query:  Select PI() * 7 ;
Result:  21,9911485751286  


  1.     SQUARE():

SQUARE() function  is used to get the square of the number as output

Example:
Query:  Select SQUARE(5);
Result:  25  

Query:  Select SQUARE(12.3); 
Result:  151,29  


  1.     ROUND():

ROUND() function is used to round value to nearest specified decimal value.

Example:
Query:  Select ROUND(10.25876,2);
Result:  10,26000  

Query:  Select ROUND(10.25876,3);
Result:  10,25900  


  1.     CEILING():

CEILING() is used to find the next highest number of given value

Example:
Query:  Select CEILING(10.258);
Result:  11  

Query:  Select CEILING(12);
Result:  12  


  1.     FLOOR():

FLOOR() is used to find the next lowest number of given value

Example:
Query:  Select FLOOR(10.258);
Result:  10  

Query:  Select FLOOR(12);
Result:  12  


 

Leave a Comment

Your email address will not be published. Required fields are marked *