ATN2 uses two components to calculate an angle while retaining its quadrant. I keep the argument order and angle unit visible. Dividing one component by the other would lose useful information and introduce a zero-denominator case.
Two points can have the same component ratio while pointing in opposite directions. The signs of both components distinguish them. The complete pair matters when a query describes direction from an origin.

Define eight simple directions
The example contains four diagonal points and four axis points. Both components use float inputs. The origin itself is excluded because this demonstration needs a defined direction away from the origin.
ATN2 receives Y first and X second. Its result is in radians, so DEGREES converts it to the unit used by the output column. An explicit decimal cast gives the comparison two fractional digits.
This is a read-only calculation with no spatial objects or schema setup. It describes a simple Cartesian coordinate convention. X grows to the right and Y grows upward for the interpretation used here.
WITH Points AS
(
SELECT CaseId, X, Y
FROM (VALUES (1, CAST(1 AS float), CAST(1 AS float)),
(2, -1, 1), (3, -1, -1), (4, 1, -1),
(5, 1, 0), (6, -1, 0), (7, 0, 1), (8, 0, -1)) AS v(CaseId, X, Y)
)
SELECT CaseId, X, Y,
CAST(DEGREES(ATN2(Y, X)) AS decimal(6,2)) AS AngleDegrees
FROM Points
ORDER BY CaseId;
Read all four quadrants
The point with X one and Y one has an expected angle of 45 degrees. Changing X to negative one moves that point to the second quadrant. Its expected angle becomes 135 degrees.
When both components are negative, the expected angle is negative 135 degrees. With positive X and negative Y, it becomes negative 45 degrees. Those signs describe directions below the positive X-axis in this convention.
The two diagonal points with equal component ratios are still distinguishable. A positive ratio alone would not identify their different quadrants. ATN2 retains the sign information from both supplied components.
The axis rows complete the example. Positive X gives zero degrees, negative X gives 180, positive Y gives 90, and negative Y gives negative 90. No division by X is needed for the vertical directions.
Keep units and conventions explicit
ATN2 returns radians, not degrees. A column labeled degrees needs an actual conversion rather than a renamed raw result. The example performs that conversion before its final presentation cast.
Its float result is approximate. The decimal output here rounds that approximate result for comparison and display. It does not turn the underlying trigonometric calculation into exact decimal arithmetic.
A screen coordinate system may make Y increase downward. That would change the directional interpretation of the same stored components. Establish the coordinate convention before describing positive and negative angles to a reader.
Swapping X and Y in the function call changes the meaning too. The query spells out ATN2(Y, X) beside its named input columns. That is easier to review than using unnamed numeric expressions.

Do not treat a planar example as a geographic calculation
These coordinates are small Cartesian components with a common origin. The query is not calculating a bearing between latitude and longitude positions. Geographic distance and direction require their own model and appropriate spatial treatment.
The example also does not normalize every angle into a zero-to-360 convention. It preserves the signed values returned by this calculation. Add a clearly defined normalization only if the consuming application requires it.
Points at the origin need a separate application rule because they do not define a direction. Do not silently assign them a meaningful heading from an incidental function result. Keeping that case outside this bounded query avoids pretending the geometry is defined.
When adapting the calculation, retain tests from every quadrant and both axes. A single diagonal test cannot expose swapped arguments or a reversed coordinate convention. The eight complete rows make those errors easier to identify.
Pass the components in the intended order, and state the unit and coordinate convention beside the calculated angle.
ATN2 is not a division, it is a direction built from two components.
Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.
Discover more from SQL Authority with Pinal Dave
Subscribe to get the latest posts sent to your email.




