# SQL Server Mathematical Functions-2

SQL Server’s mathematical functions assist in calculating values. The functions will assist with fundamental addition, subtraction, multiplication, and division, among other things. Let’s take a look at each one with an example.

Mathematical Functions:

• POWER(x,y)
This function returns the value of x raised to the power of Y.
Example: SELECT POWER(3,3)
Result: 27
Returns radians when a numeric expression, in degrees, is entered.
Result: 1.74532925199433E-309
Result: -0.785572696322647701
• RAND(x)
Returns a pseudo-random float value from 0 through 1, exclusive.
Repetitive calls of RAND() with the same seed value return the same results.Example: SELECT RAND(10)
Result: 0.713759689954247

For one connection, if RAND() is called with a specified seed value, all subsequent calls of RAND() produce results based on the seeded RAND() call. For example, the following query will always return the same sequence of numbers.

DECLARE @counter SMALLINT;
SET @counter = 1;
WHILE @counter < 5
BEGIN
SELECT RAND() Random_Number
SET @counter = @counter + 1
END;
GO

Output:
0.182458908613686, 0.586642279446948, 0.852383912025182, 0.412267217007988

• ROUND(x,y)
This function returns the value of X rounded off to the whole integer that is nearest to it.
Example: SELECT ROUND(6.899889,4)
Result: 6.899900
• SIGN(x)
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.
Example: SELECT SIGN(10)
Result: 1

• SIN(x)
Returns the trigonometric sine of the specified angle, in radians, and in an approximate numeric, float, expression.
Example: SELECT SIN(30.281719)
Result: -0.906199364985373
• SQRT(x)
This function returns the square root of X.
Example: SELECT SQRT(16)
Result: 4
• SQUARE(x)
Returns the square of the specified float value.
Example: SELECT SQUARE(4)
Result: 16
• TAN(x);
Returns the tangent of the input expression.
Example: SELECT TAN(.45);
Result: 0.483055065616578
• Remainer from a division:
SQL MOD() function is used to get the remainder from a division.
Example: SELECT 20%6 for MOD
Result: 2