SQL Server SIN() Function

The SQL Server SIN() function is a mathematical function used to return the sine value of a given angle.

Syntax

The syntax for the SIN() function is as follows:

SIN(angle)

Where the angle parameter represents the angle in radians.

Usage

The SIN() function is typically used to calculate the length of sides or angles in a triangle, as well as other mathematical calculations that require the use of the sine value.

Examples

Here are two examples of using the SIN() function:

Example 1

Assuming we have a triangle with an angle of 45 degrees, we can use the SIN() function to calculate the length of its hypotenuse.

DECLARE @angle FLOAT = 45;
DECLARE @pi FLOAT = PI();

SELECT SIN(@angle / 180 * @pi) * 10 AS Hypotenuse;

The output will be:

Hypotenuse
7.071068

Example 2

Assuming we have a table that contains angles and radii, we can use the SIN() function to calculate the sine value of each angle.

CREATE TABLE Angles (
  Angle FLOAT,
  Radius FLOAT
);

INSERT INTO Angles VALUES (0, 1);
INSERT INTO Angles VALUES (30, 1);
INSERT INTO Angles VALUES (45, 1);
INSERT INTO Angles VALUES (60, 1);
INSERT INTO Angles VALUES (90, 1);

SELECT Angle, SIN(Angle / 180 * PI()) AS SinValue
FROM Angles;

The output will be:

Angle SinValue
0 0
30 0.5
45 0.707106781186548
60 0.866025403784439
90 1

Conclusion

The SIN() function is a commonly used mathematical function used to calculate the sine value of a given angle. It is typically used to calculate the length of sides or angles in a triangle, as well as other mathematical calculations that require the use of the sine value.