In SQL Server, the ATN2()
function returns the arctangent between two values. Specifically, it returns the angle, in radians, between the positive x-axis and the ray from the origin to the point (y, x), where x and y are the values of the two specified float expressions.
You provide the values as arguments when calling the function.
Syntax
The syntax goes like this:
ATN2 ( float_expression , float_expression )
Where float_expression is an expression of data type float.
Example 1 – Basic Usage
Here’s a basic example that returns the arc tangent of two values.
SELECT ATN2(2, 3) Result;
Result:
+-------------------+ | Result | |-------------------| | 0.588002603547568 | +-------------------+
And with another set of values.
SELECT ATN2(1.3, 235.70) Result;
Result:
+---------------------+ | Result | |---------------------| | 0.00551542985993961 | +---------------------+
Example 2 – Negative Values
And with negative values.
SELECT ATN2(-1.3, -235.70) Result;
Result:
+-------------------+ | Result | |-------------------| | -3.13607722372985 | +-------------------+
And with a positive and a negative:
SELECT ATN2(1.3, -235.70) Result;
Result:
+------------------+ | Result | |------------------| | 3.13607722372985 | +------------------+
Example 3 – Expressions
You can also pass in expressions like this:
SELECT ATN2(2.5 + 0.3, 5) Result;
Result:
+-------------------+ | Result | |-------------------| | 0.510488321916776 | +-------------------+
Example 4 – Passing in a Function
In this example I pass in the T-SQL PI()
function as one of the arguments.
SELECT ATN2(PI(), 2) Result;
Result:
+------------------+ | Result | |------------------| | 1.00388482185389 | +------------------+