Wednesday, August 12, 2015

Mathematical Functions


SQL ABS Function


In SQL Server, ABS is a Mathematical Function which will return the absolute (Positive) value of the specified expression.
SQL ABS Function Syntax
In SQL Server, The basic syntax of the ABS Function is:
In this article we will show you, How to write ABS Function in SQL Server 2014 with example. For this, We are going to use the below shown data
SQL ABS FUNCTION

SQL ABS Function Example 1

ABS Function is used to return the positive value of any numeric value. The following query will show multiple ways to use ABS function.
T-SQL CODE
OUTPUT
SQL ABS FUNCTION 1
Analysis
Below lines of code is used to declare Int variable and assigning the value.
In the below statement, We used ABS function to find the absolute value of the variable @i (It means ABS(-25.8)). We also assigned new name to that result as ‘Absolute Value’ using ALIAS Column.
In the next statement, We used the ABS Function directly on the int value.
In the below statement, We used the ABS Function directly on the multiple values.
It means
ABS(2 + 55 – 77)
ABS (-20) = 20

SQL ABS Function Example 2

ABS Function also allows you to find the absolute values of a column values.  In this example, We are going to find the absolute values for all the records present in [Service Grade] using ABS Function.
T-SQL CODE
OUTPUT
SQL ABS FUNCTION 2
Thank You for Visiting Our Blog



SQL ACOS Function


In SQL Server, ACOS is a Mathematical Function which is used to calculate the trigonometry Arccosine for the specified expression. Arccosine is also called as inverse of a cosine, Please refer SQL COS Function article to understand the Cosine Function.
SQL ACOS Function Syntax
In SQL Server, The basic syntax of the ACOS Function is:
TIP: The ACOS function only accepts float values between -1 and 1.
In this article we will show you, How to write ACOS Function in SQL Server 2014 with example. For this, We are going to use the below shown data
SQL ACOS FUNCTION

SQL ACOS Function Example 1

ACOS Function is used to calculate the Arccosine for the given angle. The following query will show multiple ways to use ACOS function.
T-SQL CODE
OUTPUT
SQL ACOS FUNCTION 1
Analysis
Below lines of code is used to declare float variable and assigning the value.
In the below statement, We used ACOS function to calculate the Arccosine value for the variable @i (It means ACOS(-0.80)). We also assigned new name to that result as ‘Arc Cosine’ using ALIAS Column.
In the next statements, We used the ACOS Function directly on the float values.

SQL ACOS Function Example 2

In this example, We are going to calculate the Arccosine value for all the records present in [Service Grade] using ACOS Function.
T-SQL CODE
OUTPUT
SQL ACOS FUNCTION 2
Thank You for Visiting Our Blog



SQL ASIN Function


In SQL Server, ASIN is a Mathematical Function which is used to calculate the trigonometry Arcsine for the specified expression. Arcsine is also called as inverse of a Sine, Please refer SQL SIN Function article to understand the Sine Function.
SQL ASIN Function Syntax
In SQL Server, The basic syntax of the ASIN Function is:
TIP: The ASIN function only accepts float values between -1 and 1.
In this article we will show you, How to write ASIN Function in SQL Server 2014 with example. For this, We are going to use the below shown data
SQL ASIN FUNCTION

SQL ASIN Function Example 1

ASIN Function is used to calculate the Arcsine for given angle. The following query will show multiple ways to use ASIN function.
T-SQL CODE
OUTPUT
SQL ASIN FUNCTION 1
Analysis
Below lines of code is used to declare float variable and assigning the value.
In the below statement, We used ASIN function to calculate the Arcsine value for the variable @i (It means ASIN(-0.80)). We also assigned new name to that result as ‘Arc Sine’ using ALIAS Column.
In the next statements, We used the ASIN Function directly on the float values.

SQL ASIN Function Example 2

In this example, We are going to calculate the Arcsine value for all the records present in [Service Grade] using ASIN Function.
T-SQL CODE
OUTPUT
SQL ASIN FUNCTION 2
Thank You for Visiting Our Blog


SQL ATAN Function


In SQL Server, ATAN is a Mathematical Function which is used to calculate the trigonometry Arctangent for the specified expression. Arctangent is also called as inverse of a Tangent, Please refer SQL TAN Function article to understand the Tangent Function.
SQL ATAN Function Syntax
In SQL Server, The basic syntax of the ATAN Function is:
In this article we will show you, How to write ATAN Function in SQL Server 2014 with example. For this, We are going to use the below shown data
SQL ATAN FUNCTION

SQL ATAN Function Example 1

ATAN Function is used to calculate the Arctangent value for the given angle. The following query will show multiple ways to use ATAN function.
T-SQL CODE
OUTPUT
SQL ATAN FUNCTION 1
Analysis
Below lines of code is used to declare float variable and assigning the value.
In the below statement, We used ATAN function to calculate the Arc Tangent value for the variable @i (It means ATAN(-208.80)). We also assigned new name to that result as ‘Arc Tangent’ using ALIAS Column.
In the next statements, We used the ATAN Function directly on the float values.

SQL ATAN Function Example 2

In this example, We are going to calculate the Arctangent value for all the records present in [Service Grade] using ATAN Function.
T-SQL CODE
OUTPUT
SQL ATAN FUNCTION 2
Thank You for Visiting Our Blog


SQL ATN2 Function


In SQL Server, ATN2 is a Mathematical Function which is used to return the angle between the positive x-axis and the line from the origin to the point (y, x).
SQL ATN2 Function Syntax
In SQL Server, The basic syntax of the ATN2 Function is:
In this article we will show you, How to write ATN2 Function in SQL Server 2014 with example. For this, We are going to use the below shown data
SQL ATN2 FUNCTION

SQL ATN2 Function Example 1

ATAN Function is used to find the Angle between the positive x-axis and the line from the origin to the point (y, x). Here the x and y values are the two argument we are going to provide for ATN2 Function. The following query will show multiple ways to use ATN2 function.
T-SQL CODE
OUTPUT
SQL ATN2 FUNCTION 1
Analysis
Below lines of code is used to declare two float variables and assigning the values.
In the below statement, We used ATN2 function to find the angle between those two variables @i and @j. We also assigned new name to that result as ‘ATN2 Function’ using ALIAS Column.
In the next statements, We used the ATN2 Functions directly on the float values. For instance below statement will find the angle between the values 100 (22.45 + 77.55), 100

SQL ATN2 Function Example 2

In this example, We are going to calculate the Angle between the values present in [Standard Cost] and [Sales Amount] using ATAN Function.
T-SQL CODE
OUTPUT
SQL ATN2 FUNCTION 2
Thank You for Visiting Our Blog


SQL CEILING Function


In SQL Server, CEILING is a Mathematical Function used to return the closest integer value which is greater than or equal to the specified expression.
SQL CEILING Function Syntax
In SQL Server, The basic syntax of the CEILING Function is:
In this article we will show you, How to write CEILING Function in SQL Server 2014 with example. For this, We are going to use the below shown data
SQL CEILING FUNCTION

SQL CEILING Function Example 1

CEILING Function is used to return the closest integer value which is greater than or equal to given numeric value. The following query will show multiple ways to use CEILING function.
T-SQL CODE
OUTPUT
SQL CEILING FUNCTION 1
Analysis
Below lines of code is used to declare float variable and assigning the value.
In the below statement, We used CEILING function to find the closest integer value of the variable @i (It means CEILING(-208.45)). We also assigned new name to that result as ‘SQL CEILING’ using ALIAS Column.
In the next statement, We used the CEILING Function directly on the int value.
In the below statement, We used the CEILING Function directly on the multiple values.
It means
CEILING (2.45 + 7.55 – 14.88)
CEILING (-4.88) = – 4

SQL CEILING Function Example 2

In this example, We are going to find the closet integer values for all the records present in [Service Grade] using CEILING Function.
T-SQL CODE
OUTPUT
SQL CEILING FUNCTION 2
Thank You for Visiting Our Blog


SQL COS Function


In SQL Server, COS is a Mathematical Function which is used to calculate the trigonometry Cosine for the specified expression. The mathematical formula for this function is:
COS(x) = Length of the Adjacent Side / Length of the Hypotenuse
SQL COS Function Syntax
In SQL Server, The basic syntax of the COS Function is:
In this article we will show you, How to write COS Function in SQL Server 2014 with example. For this, We are going to use the below shown data
SQL COS FUNCTION

SQL COS Function Example 1

COS Function is used to calculate the Cosine for given angle. The following query will show multiple ways to use COS function.
T-SQL CODE
OUTPUT
SQL COS FUNCTION 1
Analysis
Below lines of code is used to declare float variable and assigning the value.
In the below statement, We used COS function to calculate the Cosine value for the variable @i (It means COS(208.45)). We also assigned new name to that result as ‘SQL Cosine’ using ALIAS Column.
In the next statements, We used the COS Function directly on the float values.

SQL COS Function Example 2

In this example, We are going to calculate the Cosine value for all the records present in [Tax Amount] and [Service Grade] using COS Function.
T-SQL CODE
OUTPUT
SQL COS FUNCTION 2
Thank You for Visiting Our Blog


SQL COT Function


In SQL Server, COT is a Mathematical Function which is used to calculate the trigonometry Cotangent for the specified expression. The mathematical formula for this function is:
COT(x) = 1 / TAN(x)
Please refer SQL TAN Function article to understand the functionality of tangent function.
SQL COT Function Syntax
In SQL Server, The basic syntax of the COT Function is:
In this article we will show you, How to write COT Function in SQL Server 2014 with example. For this, We are going to use the below shown data
SQL COT FUNCTION

SQL COT Function Example 1

COT Function is used to calculate the Cotangent value for the given angle. The following query will show multiple ways to use COT function.
T-SQL CODE
OUTPUT
SQL COT FUNCTION 1
Analysis
Below lines of code is used to declare float variable and assigning the value.
In the below statement, We used COT function to calculate the Cotangent value for the variable @i (It means COT(208.45)). We also assigned new name to that result as ‘SQL Cotangent’ using ALIAS Column.
In the next statements, We used the COT Function directly on the float values.

SQL COT Function Example 2

In this example, We are going to calculate the Cotangent value for all the records present in [Tax Amount] and [Service Grade] using COT Function.
T-SQL CODE
OUTPUT
SQL COT FUNCTION 2
Thank You for Visiting Our Blog


SQL FLOOR Function


In SQL Server, FLOOR is a Mathematical Function used to return the closest integer value which is less than or equal to the specified expression.
SQL FLOOR Function Syntax
In SQL Server, The basic syntax of the FLOOR Function is:
In this article we will show you, How to write FLOOR Function in SQL Server 2014 with example. For this, We are going to use the below shown data
SQL FLOOR FUNCTION

SQL FLOOR Function Example 1

FLOOR Function is used to return the closest integer value which is less than or equal to given numeric value. The following query will show multiple ways to use FLOOR function.
T-SQL CODE
OUTPUT
SQL FLOOR FUNCTION 1
Analysis
Below lines of code is used to declare float variable and assigning the value.
In the below statement, We used FLOOR function to find the closest integer value of the variable @i (It means FLOOR(-208.45)). We also assigned new name to that result as ‘SQL FLOOR’ using ALIAS Column.
In the next statement, We used the FLOOR Function directly on the float value.
In the below statement, We used the FLOOR Function directly on the multiple values.
It means
FLOOR (2.45 + 7.55 – 14.88)
FLOOR (-4.88) = – 5

SQL FLOOR Function Example 2

In this example, We are going to find the closet integer values for all the records present in [Service Grade] using FLOOR Function.
T-SQL CODE
OUTPUT
SQL FLOOR FUNCTION 2
Thank You for Visiting Our Blog


SQL POWER Function


In SQL Server, POWER is a Mathematical Function used to calculate the power for the specified expression.
SQL POWER Function Syntax
In SQL Server, The basic syntax of the POWER Function is:
In this article we will show you, How to write POWER Function in SQL Server 2014 with example. For this, We are going to use the below shown data
SQL POWER FUNCTION

SQL POWER Function Example 1

POWER Function is used to calculate the power of a given numeric value. The following query will show multiple ways to use POWER function.
T-SQL CODE
OUTPUT
SQL POWER FUNCTION 1
Analysis
Below lines of code is used to declare float and int variable and assigning the values.
In the below statement, We used POWER function to calculate the power of the variable @i. We also assigned new name to that result as ‘SQL Power’ using ALIAS Column.
It means,
@i * @i * @i  = 2 * 2 * 2 = 8
In the next statement, we used 4 as second argument. It means 2 * 2 * 2 * 2 = 16
In the next statement, We used the integer value as input for the POWER function.
It means
POWER (@j, 3) = @j * @j * @j
                        = 2.20 * 2.20 * 2.20 = 10.65
But we are getting 8 as a result because it is rounding the 2.20 value to 2
NOTE: Please use float variables as a input for POWER Function otherwise, you may expect strange results.

SQL POWER Function Example 2

Power Function also allows you to calculate the power of column values. In this example, We are going to calculate the power of three for all the records present in [Sales Amount] using POWER Function.
T-SQL CODE
OUTPUT
SQL POWER FUNCTION 2
Thank You for Visiting Our Blog


SQL SIN Function


In SQL Server, SIN is a Mathematical Function which is used to calculate the trigonometry sine for the specified expression. The mathematical formula for this function is:
SIN(x) = Length of the Opposite Side / Length of the Hypotenuse
SQL SIN Function Syntax
In SQL Server, The basic syntax of the SIN Function is:
In this article we will show you, How to write SIN Function in SQL Server 2014 with example. For this, We are going to use the below shown data
SQL SIN FUNCTION 1

SQL SIN Function Example 1

SIN Function is used to calculate the sine for given angle. The following query will show multiple ways to use SIN function.
T-SQL CODE
OUTPUT
SQL SIN FUNCTION 1
Analysis
Below lines of code is used to declare float variable and assigning the value.
In the below statement, We used SIN function to calculate the sine value for the variable @i (It means SIN(208.45)). We also assigned new name to that result as ‘SQL SINE’ using ALIAS Column.
In the next statements, We used the SIN Function directly on the float values.

SQL SIN Function Example 2

In this example, We are going to calculate the sine value for all the records present in [Tax Amount] and [Service grade] using SIN Function.
T-SQL CODE
OUTPUT
SQL SIN FUNCTION 2
Thank You for Visiting Our Blog