SQL ATN2 function (SQL Server)
Returns the angle whose tangent is y/x, using both signs to place the angle in the correct quadrant: ATN2(1, 1) is PI()/4.
- 카테고리
- Math
- Returns
float (radians)- In this category
- 38 of 82
구문
ATN2(y, x)
엔진 지원
| 엔진 | Support | 메모 |
|---|---|---|
| SQL Server | 예 | Supported under this name. |
| PostgreSQL | Not built in | Use atan2(y, x) |
| MySQL | Not built in | Use ATAN2(y, x) or ATAN(y, x) |
| SQLite | Not built in | Use atan2(y, x) on 3.35+ |
| Oracle | Not built in | Use ATAN2(y, x) |
예시
SQL Server
SELECT ATN2(1, 1) AS quarter_pi; -- 0.7853981...
SQL Server
SELECT DEGREES(ATN2(delta_y, delta_x)) AS bearing_deg FROM nav_fixes;
알아 두면 좋은 정보
- The order is y first, x second, matching ATAN2 everywhere else, so a cross-engine rewrite only renames the function.
- ATN2(-1, 1) is -PI()/4 and ATN2(1, -1) is 3*PI()/4: signs matter, unlike ATAN which folds everything into (-PI/2, PI/2). ATN2(0, 0) raises an invalid floating point operation.
- The result is a float in radians; DEGREES(ATN2(y, x)) converts for display.
Questions about ATN2
Is ATN2 the same as ATAN2?
Yes: same math, same (y, x) argument order. SQL Server spells it ATN2; PostgreSQL, MySQL, SQLite and Oracle spell it ATAN2.
What does ATN2(0, -1) return?
PI(), about 3.14159: the point (-1, 0) sits on the negative x-axis, and only a two-argument arc tangent can place it there.
How do I convert ATN2 output to degrees?
Wrap it: DEGREES(ATN2(y, x)). The function itself always returns radians as a float.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: SQL Server.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.