SQL Server RADIANS() Function

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

Introduction to the SQL Server RADIANS() function

The RADIANS() is a math function that allows you to convert degrees to radians.

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

RADIANS(numeric_expression)Code language: SQL (Structured Query Language) (sql)

In this syntax,

  • numeric_expression is a number in degrees that you want to convert to radians.

The RADIANS() function returns the numeric_expression converted to radians.

The return type of the RADIANS() 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 numeric_expression is NULL, the RADIANS() function returns NULL.

SQL Server RADIANS() function examples

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

1) Basic RADIANS() function example

The following statement uses the RADIANS() function to convert 180 degrees to its equivalent in radians, resulting in PI value:

SELECT RADIANS(180.00) radians;Code language: SQL (Structured Query Language) (sql)

Output:

      radians
-------------------
 3.141592653589793Code language: SQL (Structured Query Language) (sql)

2) Using the RADIANS() function with table data

First, create a new table called measurements to store angle data in radians:

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

Second, insert some rows into the measurements table:

INSERT INTO measurements(angle_degrees) 
VALUES
    (45),
    (60),
    (90),
    (NULL);Code language: SQL (Structured Query Language) (sql)

Third, retrieve data from the measurements table:

SELECT * FROM measurements;

Output:

id | angle_degrees
---+--------------
1  | 45.00
2  | 60.00
3  | 90.00
4  | NULLCode language: SQL (Structured Query Language) (sql)

Third, convert the values in the angle_degrees column to radians using the RADIANS() function:

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

Output:

id | angle_degrees | angle_radians
---+---------------+---------------------
1  | 45.00         | 0.785398163397448279
2  | 60.00         | 1.047197551196597631
3  | 90.00         | 1.570796326794896558
4  | NULL          | NULLCode language: SQL (Structured Query Language) (sql)

Summary

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