SQL Server DEGREES() Function

Summary: in this tutorial, you will learn how to use the SQL Server DEGREES() function to convert radians to degrees.

Introduction to the SQL Server DEGREES() function

In SQL Server, the DEGREES() function is a math function that allows you to convert radians to degrees.

The following shows the syntax of the DEGREES() function:

DEGREES(numeric_expresion)Code language: SQL (Structured Query Language) (sql)

In this syntax, the numeric_expresion is a value in radians that you want to convert to degrees.

The DEGREES() function returns the value of the numeric_expresion converted to degrees.

The return type of the DEGREES() function depends on the input type of the numeric_expression.

The following table shows the input type of the numeric_expression and the corresponding return type:

Input typeReturn type
float, realfloat
decimal(p, s)decimal(38, s)
int, smallint, tinyintint
bigintbigint
money, smallmoneymoney
bitfloat

If the radians_value is NULL, the DEGREES() function returns NULL.

SQL Server DEGREES() function examples

Let’s explore some examples of using the DEGREES() function.

1) Basic DEGREES() function examples

The following statement uses the DEGREES() function to convert 1.00 radian to its equivalent degrees:

SELECT DEGREES(1.00) degrees;Code language: SQL (Structured Query Language) (sql)

Output:

degrees
---------------------
57.295779513082322865
Code language: SQL (Structured Query Language) (sql)

The following statement uses the DEGREES() function to convert the value of π (pi) radians to its equivalent in degrees:

SELECT DEGREES(PI()) degrees;Code language: SQL (Structured Query Language) (sql)

Output:

degrees
-------
180.0Code language: SQL (Structured Query Language) (sql)

Note that the PI() function returns the value of π (pi) radians.

2) Using the DEGREES() function with table data

First, create a new table called measurements to store radian data:

CREATE TABLE measurements (
    id INT IDENTITY PRIMARY KEY,
    angle_radians DEC(10,2)
);Code language: SQL (Structured Query Language) (sql)

Second, insert some rows into the measurements table:

INSERT INTO measurements (angle_radians) 
VALUES
    (2*PI()),
    (PI()),
    (PI()/2),
    (NULL);Code language: SQL (Structured Query Language) (sql)

Third, convert radians stored in the measurements table to degrees using the DEGREES() function:

SELECT
  id,
  angle_radians,
  DEGREES(angle_radians) AS angle_degrees
FROM
  measurements;Code language: SQL (Structured Query Language) (sql)

Output:

id | angle_radians | angle_degrees
---+---------------+-----------------------
1  | 6.28          | 359.817495342156973948
2  | 3.14          | 179.908747671078486974
3  | 1.57          | 89.954373835539243487
4  | NULL          | NULLCode language: SQL (Structured Query Language) (sql)

Summary

  • Use the SQL Server DEGREES() function to convert radians to degrees.
Was this tutorial helpful?