SQL Server RADIANS()



SQL Server RADIANS() Function

The SQL Server RADIANS() function converts an angle from degrees to radians. This function is useful for trigonometric calculations that require angle measurements in radians.


Syntax

SELECT RADIANS(angle_in_degrees);

The RADIANS() function takes a single argument:

  • angle_in_degrees: The angle in degrees to be converted to radians.

Example SQL Server RADIANS() Function Queries

Let's look at some examples of SQL Server RADIANS() function queries:

1. Basic RADIANS() Example

SELECT RADIANS(180) AS result;

This query converts the angle 180 degrees to radians. The result will be:

result
------
3.141592653589793

2. RADIANS() with 90 Degrees

SELECT RADIANS(90) AS result;

This query converts the angle 90 degrees to radians. The result will be:

result
------
1.5707963267948966

3. RADIANS() with a Column

SELECT angle_in_degrees, RADIANS(angle_in_degrees) AS angle_in_radians
FROM angles;

This query converts the angles in the angle_in_degrees column to radians for each record in the angles table. The result will show the original angle_in_degrees and its corresponding angle_in_radians.

4. RADIANS() with a Variable

DECLARE @angle FLOAT;
SET @angle = 60;
SELECT RADIANS(@angle) AS result;

This query uses a variable to store an angle in degrees and then converts it to radians. The result will be:

result
------
1.0471975511965976

Full Example

Let's go through a complete example that includes creating a table, inserting data, and using the RADIANS() function.

Step 1: Creating a Table

This step involves creating a new table named angles to store some sample data.

CREATE TABLE angles (
    id INT PRIMARY KEY,
    angle_in_degrees FLOAT
);

In this example, we create a table named angles with columns for id and angle_in_degrees.

Step 2: Inserting Data into the Table

This step involves inserting some sample data into the angles table.

INSERT INTO angles (id, angle_in_degrees) VALUES (1, 180);
INSERT INTO angles (id, angle_in_degrees) VALUES (2, 90);
INSERT INTO angles (id, angle_in_degrees) VALUES (3, 60);
INSERT INTO angles (id, angle_in_degrees) VALUES (4, 45);

Here, we insert data into the angles table.

Step 3: Using the RADIANS() Function

This step involves using the RADIANS() function to convert the angle_in_degrees column to radians.

SELECT id, angle_in_degrees, RADIANS(angle_in_degrees) AS angle_in_radians
FROM angles;

This query retrieves the id, angle_in_degrees, and the angle in radians for each row in the angles table. The result will be:

id  angle_in_degrees  angle_in_radians
--- ----------------- -----------------
1   180               3.141592653589793
2   90                1.5707963267948966
3   60                1.0471975511965976
4   45                0.7853981633974483

Conclusion

The SQL Server RADIANS() function is a powerful tool for converting an angle from degrees to radians. Understanding how to use the RADIANS() function and its syntax is essential for effective trigonometric calculations and data processing in SQL Server.