Friday, 4 May 2012

Sql Server material 10


POWER(n, m): Returns the value of the specified expression n to the specified power m.
            SELECT POWER(10, 3)                                OUTPUT: 1000

RAND ( [SEED] ): Returns a random float value from 0 through 1.
-          SEED: Is an integer expression that gives the seed value. If seed is not specified, the Database Engine assigns a seed value at random. For a specified seed value, the result returned is always the same.
SELECT RAND()      -Each time we execute we get a random value.
SELECT RAND(100)            -Each time we execute we get the same value.                      

ROUND ( n , length [ ,function ] ): Returns a numeric expression, rounded to the specified length or precision.
            SELECT ROUND(156.567, 2)                      OUTPUT: 156.57
            SELECT ROUND(156.567, 1)                      OUTPUT: 156.6
            SELECT ROUND(156.567, 0)                      OUTPUT: 157
-If the seed is positive rounding will be done after the decimal, if it is negative rounding will be done before the decimal:
            SELECT ROUND(156.567, -1)                     OUTPUT: 160
            SELECT ROUND(156.567, -2)                     OUTPUT: 200
-If we specify the optional parameter function that is an integer value we can decide to truncate the value or round the value. If it is 0 (default) rounds the value and value greater than 0 truncates the value.
            SELECT ROUND(156.567, 2, 1)                  OUTPUT: 156.56
            SELECT ROUND(156.567, -2, 1)                 OUTPUT: 100

SIGN(n):  Returns the positive (+1), zero (0), or negative (-1) sign of the specified expression.
-          If n<0 it returns -1
-          If n=0 it returns 0
-          If n>0 it returns 1
SELECT SIGN(-100)                                     OUTPUT: -1
SELECT SIGN(0)                                          OUTPUT: 0
SELECT SIGN(100)                                      OUTPUT: 1

SQRT(n): Returns the square root of the specified expression.
            SELECT SQRT(81)                                        OUTPUT: 9
SELECT SQRT(30)                                        OUTPUT: 5.47722557505166

SQUARE(n): Returns the square of the specified expression.
            SELECT SQUARE(35)                                 OUTPUT: 1225

-Apart from the above it provides with trigonometric function like COS, COT, SIN, TAN, ACOS, ASIN, ATAN for which we need to provide the degrees.

<<< Previous                                                                                                                          Next >>>

No comments:

Post a Comment