SQL Server Mathematical Functions-2

For the previous post, click here.

As stated earlier, mathematical Functions are built-in scalar functions that perform calculations depending on input values provided as arguments and return a numeric value.

We’ll go through the remaining mathematical functions that SQL Server has to offer in this post.

SELECT COT(124.1332)
Results: -0.0403119983711489
A mathematical function that returns the trigonometric cotangent of the specified angle – in radians – in the specified float expression.

SELECT DEGREES((PI()/2))
Results: 90
This function returns the corresponding angle, in degrees, for an angle specified in radians.

SELECT EXP(2)
Results: 7.38905609893065
Returns the exponential value of the specified float expression.
Explanation:
The constant e (2.718281…), is the base of natural logarithms.
The exponent of a number is the constant e raised to the power of the number. For example EXP(1.0) = e^1.0 = 2.71828182845905 and EXP(10) = e^10 = 22026.4657948067.
The exponential of the natural logarithm of a number is the number itself: EXP (LOG (n)) = n.
And the natural logarithm of the exponential of a number is the number itself: LOG (EXP (n)) = n.

SELECT FLOOR(6.8)
Results: 6
This returns the smallest integer value that is either more than X or equal to it.

SELECT LOG(10)
Results: 2.30258509299405
In SQL Server, this function returns the natural logarithm of the provided float expression.
LOG() returns the natural logarithm by default. With SQL Server 2012 (11.x), you can use the optional base parameter to alter the logarithm’s base to a different value.
The natural logarithm is the logarithm to the base e, where e is an irrational constant with a value of about 2.718281828.
The number itself is the natural logarithm of the exponential of a number: LOG(EXP(n)) = n. And the number itself is the exponential of the natural logarithm: EXP(LOG(n)) = n.

SELECT LOG10(145.175643)
Results: 2.16189375825097
Returns the base-10 logarithm of the specified float expression.
The LOG10 and POWER functions are inversely related to one another. For example, 10 ^ LOG10(n) = n.

SELECT PI()
Results: 3.14159265358979
Returns the constant value of PI.

SELECT POWER(3,3)
Results: 27
This function returns the value of x raised to the power of Y.

SELECT RADIANS(1e-307)
Results: 1.74532925199433E-309

SELECT RADIANS(-45.01)
Results: -0.785572696322647701
Returns radians when a numeric expression, in degrees, is entered.

SELECT RAND(10)
Results: 0.713759689954247
Returns a pseudo-random float value from 0 through 1, exclusive.
Repetitive calls of RAND() with the same seed value return the same results.

SELECT ROUND(6.899889,4)
Results: 6.899900
This function returns the value of X rounded off to the whole integer that is nearest to it.

SELECT SIGN(10)
Results: 1
This method returns 1 if X is positive, -1 if it is negative and 0 if the value of X is 0.
Returns the positive (+1), zero (0), or negative (-1) sign of the specified expression.

SELECT SIN(30.281719)
Results: -0.906199364985373
Returns the trigonometric sine of the specified angle, in radians, and in an approximate numeric, float, expression.

SELECT SQRT(16)
Results: 4
This function returns the square root of X.

SELECT SQUARE(4)
Results: 16
Returns the square of the specified float value.

SELECT TAN(.45);
Results: 0.483055065616578
Returns the tangent of the input expression.

SELECT 20%6
Results: 2
The above method is used to get the remainder from a division.

I hope you found this post to be informative.

Please join our mailing list to receive more interesting information.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s