SQL Server DEGREES() Function

The SQL Server DEGREES() function is used to convert radians to degrees. In SQL Server, the calculation parameter of trigonometric functions is in radians. To better understand and use trigonometric functions, it is often necessary to convert angle values to radians, which can be easily done using the DEGREES() function.

Syntax

DEGREES(numeric_expression)

Use Cases

In SQL Server, the calculation parameter of trigonometric functions is in radians. To better understand and use trigonometric functions, it is often necessary to convert angle values to radians. For example, when calculating the value of a sine function, if the parameter is in degrees, it needs to be converted to radians before calculation. The DEGREES() function can convert radians to degrees, making it more convenient to use trigonometric functions.

Examples

Example 1

Use the DEGREES() function to convert radians to degrees.

SELECT DEGREES(PI()) AS Result;

Result:

Result
180

Explanation: The PI() function returns the value of pi, and the DEGREES() function converts it to degrees 180.

Example 2

Convert angle values to radians, and then calculate the sine value using the SIN() function.

DECLARE @angle INT = 30;
DECLARE @rad FLOAT = PI() / 180 * @angle;

SELECT SIN(@rad) AS Result;

Result:

Result
0.500000000000000

Explanation: First, the angle value is converted to radians, and then the SIN() function is used to calculate the sine value, resulting in a result of 0.5.

Conclusion

The SQL Server DEGREES() function can convert radians to degrees, making it more convenient to use trigonometric functions. When calculating the value of trigonometric functions, if the parameter is in degrees, the DEGREES() function can be used to convert it to radians before calculation.