SQL ATN2 Function Syntax
In SQL Server, The basic syntax of the ATN2 Function is:
SELECT ATN2 (Float_Expression, Float_Expression) FROM [Source]
In this article we will show you, How to write or use ATN2 Function in SQL Server with example. For this, We are going to use the below shown data
SQL ATN2 Function Example 1
The ATAN2 Function is used to find the Angle between the positive x-axis and the line from the origin to the point (y, x). Here the x and y values are the two argument we are going to provide for ATN2 Function. The following query will show multiple ways to use ATN2 function.
DECLARE @i Float = 50.05, @j Float = 200.05 SELECT ATN2(@i, @j) AS [ATN2 Function] -- Calculating ATAN directly SELECT ATN2(100.27, 50.27) AS [ATN2 Function] -- Calculating ATAN directly SELECT ATN2(22.45 + 77.55, 100) AS [ATN2 Function]
Below lines of code is used to declare two float variables and assigning the values.
DECLARE @i Float = 50.05, @j Float = 200.05
In the below statement, We used ATN2 function to find the angle between those two variables @i and @j. We also assigned new name to that result as ‘ATN2 Function’ using ALIAS Column.
SELECT ATN2(@i, @j) AS [ATN2 Function]
In the next statements, We used the ATN2 Functions directly on the float values. For instance below statement will find the angle between the values 100 (22.45 + 77.55), 100
-- Calculating ATAN directly SELECT ATN2(22.45 + 77.55, 100) AS [ATN2 Function]
SQL ATN2 Function Example 2
In this example, We are going to calculate the Angle between the values present in [Standard Cost] and [Sales Amount] using Sql Server ATN2 Function.
SELECT [EnglishProductName] ,[Color] ,[StandardCost] ,[SalesAmount] ,ATN2([StandardCost], [SalesAmount]) AS [ATN2 Function] FROM [Mathemetical Functions]
Thank You for Visiting Our Blog