Summary: in this tutorial, you will learn how to use the SQL Server ATAN() function to return the arctangent of a number.
Introduction to the SQL Server ATAN() function #
In math, the arctangent function is the inverse function of the tangent function. The arctangent is the angle in radians whose tangent is a specified number.
In SQL Server, you can use the ATAN() function to calculate the arctangent of a number.
The syntax of the ATAN() function is as follows:
ATAN(n)Code language: SQL (Structured Query Language) (sql)In this syntax:
nis a value you want to calculate the arctangent.
The ATAN() function returns an angle (in radians) of the n. If n is NULL, the ATAN() function will return NULL.
SQL Server ATAN() function examples #
Let’s explore some examples of using the ATAN() function.
1) Basic SQL Server ATAN() function example #
The following example uses the ATAN() function to return the arctangent of zero radian:
SELECT ATAN(0) angle;Code language: SQL (Structured Query Language) (sql)Output:
angle
-----
0Code language: SQL (Structured Query Language) (sql)2) Using the ATAN() function with variables #
The following example shows how to use the ATAN() function with variables:
DECLARE @value FLOAT;
SET @value = PI()/2;
SELECT ATAN(@value) AS arctangent_value;Code language: SQL (Structured Query Language) (sql)Output:
arctangent_value
----------------
1.00388482185389Code language: SQL (Structured Query Language) (sql)In this example, we set the @value to PI/2 and then use the ATAN() function to calculate its arctangent, which is approximately 1.00388482185389.
Summary #
- Use the
ATAN()function to return the arctangent of a number.