top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to Work with RAND FLOOR LOG LOG10 EXP functions in SQL server 2008?

0 votes
396 views
How to Work with RAND FLOOR LOG LOG10 EXP functions in SQL server 2008?
posted Mar 21, 2016 by Latha

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

RAND ()

RAND () is one of the most commonly used MATH functions in SQL Server. It is used to find the pseudo-random number.

It takes only one parameter; ‘seed’ for the function which is optional. This function can execute without any seed value. Input parameter value should be of type integer which can classify into int, smallint, tinyint. It returns a float value which is the pseudo-random number and also it is any float value between 0 and 1.

Syntax:

RAND (float_expression)

Example:

SELECT RAND(), RAND()



Output:
-------------
0.348327709542852  0.786995868228846

If ‘seed’ is provided to the function, then result will be according to that seed. For Example,

Example:

SELECT RAND(25), RAND()

Output:
-------------
0.71403918452312  0.366154723070577

For same seed, it will produce the same result every time. Also, the subsequent calls, after the function call which was provided the seed value, will produce the same result every time. The result will not change if the seed value is same even for new connection.

FLOOR ()
FLOOR () is one of the most commonly used MATH functions in SQL Server. It is used to find the value less than or equal to the given numerical expression (very previous one). Any numeric data type can be used as an expression.

It takes only one parameter which can be any numerical expression except ‘bit’ data type. And this function returns the same data type as it receive as parameter

Syntax:

FLOOR (numerical_expression)

Example:

SELECT FLOOR(25.45), FLOOR (-25.45), FLOOR (0.0)




Output:
-------------
25  -26  0

EXP ()
EXP () is one of the most commonly used MATH functions in SQL Server. It is used to find the exponential value of the given number.

It takes only one parameter, the value, for which the exponential value has to be find. Input parameter is of float type or any data type can be used which can be explicitly converted to the float data type.

Syntax:

EXP (float_expression)

Example:

SELECT EXP(2.5)



Output:
-------------
12.1824939607035

If exponential of any logarithm value is tried to find out, it will the given number itself. As, the constant e, is the base of the natural logarithm having value approx. 2.718281….
It means if you try to find out the exponential value for any given input it will be e^input. For example, EXP (2.5) = e^2.5
Therefore, if logarithm value is given as input:

Example:

SELECT EXP(LOG(2.5))



Output:
-------------
2.5

The result for the above example is the value itself as the both functions are inverse functions of each other.

LOG ()
LOG () is one of the most commonly used MATH functions in SQL Server. It is used to find the natural logarithm value of the given number.

It takes only one parameter, the value, for which the logarithm value has to be find. Input parameter is of float type or any data type can be used which can be explicitly converted to the float data type.

Syntax:

LOG (float_expression)

Example:

SELECT LOG(10)



Output:
-------------
2.30258509299405

If logarithm of any exponential value is tried to find out, it will the given number itself. As, the constant e, is the base of the natural logarithm having value approx. 2.718281….
It means if you try to find out the exponential value for any given input it will be e ^ input. For example, EXP (2.5) = e^2.5
Therefore, if exponential value is given as input:

Example:

SELECT LOG(EXP(10))



Output:
-------------
10

The result for the above example is the value itself as the both functions are inverse functions of each other.

LOG10 ()

LOG10 () is one of the most commonly used MATH functions in SQL Server. It is used to find the base 10 logarithm value of the given number.

It takes only one parameter, the value, for which the logarithm value has to be find. Input parameter is of float type or any data type can be used which can be explicitly converted to the float data type.

Syntax:

LOG (float_expression)

Example:

SELECT LOG10(10), LOG10(2.5)



Output:
-------------
1  0.397940008672038

Here, it can be said that the any POWER taken for the value of 10 and the LOG10 functions are inversely related to each other. As, 10 ^ LOG10 (n) = n or vice versa, where n, is any natural number.

Example:

SELECT POWER (10, LOG10(7));



Output:
-------------
7
answer Mar 21, 2016 by Shivaranjini
...