SQL Server ATAN() Function

In SQL Server, the ATAN() function is used to return the arctangent of a given number. The arctangent function returns an angle value, which is between -π/2 and π/2.

Syntax

ATAN(numeric_expression)

Here, numeric_expression is the numeric expression for which the arctangent value is to be computed.

Use Cases

A common use case for this function is in angle calculations. For example, the arctangent function can be used to calculate the angle value in a right triangle.

Examples

Example 1

Suppose there is a students table in which the names and math scores of students are stored:

name math_score
Alice 90
Bob 75
Charlie 82

Now, we want to add the angle value corresponding to the math score in the query result. We can use the ATAN() function to calculate it.

SELECT name, math_score, ATAN(math_score) as angle
FROM students;

Query result:

name math_score angle
Alice 90 1.47112767
Bob 75 1.320618
Charlie 82 1.40479633

In this example, we applied the ATAN() function to the math score column and obtained the corresponding angle value.

Example 2

Suppose we need to calculate the arctangent value for a number of 1. We can use the ATAN() function.

SELECT ATAN(1);

Query result:

(No column name)
0.7853981633974483

In this example, we used the ATAN() function to calculate the arctangent value for the number 1 and returned the corresponding angle value.

Conclusion

The ATAN() function is a useful mathematical function commonly used in angle calculations. Its returned value is an angle value, which is between -π/2 and π/2.