T-SQL ATN2() Function
The T-SQL (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:
Data | y | x |
---|---|---|
Data 1 | 10 | 10 |
Data 2 | -10 | 10 |
Data 3 | 10 | -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:
Data | y | x | ATN2_Value |
---|---|---|---|
Data 1 | 10 | 10 | 0.7853981633974483 |
Data 2 | -10 | 10 | -0.7853981633974483 |
Data 3 | 10 | -10 | 2.356194490192345 |
Data 4 | -10 | -10 | -2.356194490192345 |
❮ T-SQL Functions