SQL Server Tutorial SQL Server Advanced SQL Server Database SQL Server References

SQL Server ATN2() Function



The SQL Server (Transact-SQL) ATN2() function returns arc tangent of two numbers. The returned value will be in the range -𝜋 through 𝜋, depending on the signs of y and x, expressed in radians.

Syntax

ATN2(y, x)

Parameters

y Required. Specify the first number used to calculate the arc tangent.
x Required. Specify the second number used to calculate the arc tangent.

Return Value

Returns the arc tangent of two numbers.

Example 1:

The example below shows the usage of ATN2() function.

SELECT ATN2(PI(), 2);
Result: 1.0038848218538872

SELECT ATN2(3, 5);
Result: 0.5404195002705842

SELECT ATN2(2, 2);
Result: 0.7853981633974483

SELECT ATN2(2, -2);
Result: 2.356194490192345

SELECT ATN2(-2, 2);
Result: -0.7853981633974483

SELECT ATN2(-2, -2);
Result: -2.356194490192345

Example 2:

Consider a database table called Sample with the following records:

Datayx
Data 11010
Data 2-1010
Data 310-10
Data 4-10-10

To calculate the arc tangent of records of column y and column x, the following query can be used:

SELECT *, ATN2(y, x) AS ATN2_Value FROM Sample;

This will produce the result as shown below:

DatayxATN2_Value
Data 110100.7853981633974483
Data 2-1010-0.7853981633974483
Data 310-102.356194490192345
Data 4-10-10-2.356194490192345

❮ SQL Server Functions