Menu

SQL Server ATAN() Function

Updated on

ATAN() returns the angle in radians whose tangent is the specified numeric ratio. The result is between -π/2 and π/2, so a single ratio cannot identify the quadrant of a point. For two coordinates, use ATN2(y, x). See Microsoft’s ATAN() reference.

Syntax

ATAN(float_expression)

float_expression must be a float or a type that SQL Server can implicitly convert to float; the return type is float.

Use case

Use ATAN() when you have a tangent ratio, such as the rise divided by the run of a line, and need its angle in radians.

Examples

Calculate an angle from rise and run

DECLARE @rise float = 1;
DECLARE @run float = 1;

SELECT ATAN(@rise / @run) AS angle_radians;

The result is approximately 0.785398 radians.

Convert the result to degrees

SELECT DEGREES(ATAN(1.0)) AS angle_degrees;

The result is 45 degrees. If both X and Y coordinates are available, use ATN2(y, x) instead; it uses both values to identify the quadrant.

Conclusion

ATAN() returns an angle in radians from a tangent ratio, but its range is limited to -π/2 through π/2. Use ATN2() when the angle must reflect the quadrant of two coordinates.