Monday, February 9, 2015

Mathematical Functions in SQL Server

9:17 AM - By ajay desai 0


(i) ABS(n): - this function returns a positive integer value of the given expression “(n)”.

   For ex: - select ABS(-1.4)
 

(ii) FLOOR(n): - this function returns the largest integer which is less than or equal to the given expression “(n)”.

     For ex: - select FLOOR(7.9)
 
 

(iii) CEILING(n): - this function returns the largest integer which is greater than or equal to the given expression “(n)”.
 
    For ex: - select ceiling(7.9)

                                                   

(iv)  Pi( ): - this function returns the constant value of pi.

      For ex: -  select PI()
   

(v)  Power(n,m): - this function returns the value of the given expression ‘n’ to the given power ‘m’.

     For ex: -select POWER(2,4)
 

(vi) Square(n): - this function returns the square of the given expression “(n)”.

     For ex: - select SQUARE(30)

 

(vii) Sqrt(n): - this function returns the square root of the given expression  “(n)”.

      For ex: - select SQRT(16)

                                                       

(viii) LOG(n): - this function returns the natural logarithm of the given expression “(n)”.

       For ex: - select LOG(10)
   
                                                    

(ix) LOG10(n): - this function returns base-10 logarithm of the given expression     “(n)”.

     For ex: - select LOG10(10)

                                                      

(x) SIGN(n): - this function returns the sign of the given expression ‘n’.

    For ex: - select SIGN(1000)
   

    For ex: - select SIGN(-1000)

                                                         

Note: - SIGN(0) is 0.


(xi) ROUND(n,length[ ,function ]): - this function returns a numeric expression ‘n’ rounded to a given precision or length.

    If the given length or precision is positive, then the number is rounded after the decimal point.

    For ex: - select ROUND(70.56,1)

                                                 

   If the given length or precision is negative, then the number is rounded before the decimal point.

   For ex: - select ROUND(70.56,-1)

                                                

(xii) RAND: - this function generates and returns a random float value from 0 to 1. This function gives a unique value after every execution.

      For ex: - select RAND()

                                               

      For ex: - select RAND(345)
   
                                               
   

In the above given example, the ‘seed’ value is 345, when the seed value is given, this function gives the same value after every execution.

Tags:
About the Author

I am Azeheruddin Khan having more than 6 year experience in c#, Asp.net and ms sql.My work comprise of medium and enterprise level projects using asp.net and other Microsoft .net technologies. Please feel free to contact me for any queries via posting comments on my blog,i will try to reply as early as possible. Follow me @fresher2programmer
View all posts by admin →

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

adsense

© 2014 Fresher2Programmer. WP Theme-junkie converted by Bloggertheme9
Powered by Blogger.
back to top