Summary: in this tutorial, you will learn how to use the SQL Server ACOS() function to return the arccosine of a number.
Introduction to the SQL Server ACOS() function #
The arccosine function is the inverse function of the cosine function. The arccosine returns the angle of a cosine in radians.
In SQL Server, you can use the ACOS() function that returns an angle (in radians) of a specified cosine.
Here’s the syntax of the ACOS() function:
ACOS(n)Code language: SQL (Structured Query Language) (sql)In this syntax:
- n is a float value you want to calculate the arccosine. The valid range of n is from -1 to 1.
The ACOS() function returns an angle (in radians) whose cosine equals the n. If n is invalid, the ACOS() function will raise an error. If n is NULL, the ACOS() function will return NULL.
SQL Server ACOS() function examples #
Let’s take some examples of using the SQL Server ACOS() function.
1) Basic SQL Server ACOS() function example #
The following example uses the ACOS() function to return the arccosine of -1:
SELECT ACOS(-1) angle;Code language: SQL (Structured Query Language) (sql)Output:
angle
-----------------
3.141592653589793Code language: SQL (Structured Query Language) (sql)It returns the PI value.
2) Using ACOS() function with variables #
The following example uses the ACOS() function with variables:
DECLARE @value FLOAT;
SET @value = 1;
SELECT ACOS(@value) AS arccosine_value;Code language: SQL (Structured Query Language) (sql)Output:
arccosine_value
---------------
0Code language: SQL (Structured Query Language) (sql)In this example, we set the @value to 1 and then use the ACOS() function to calculate the arccosine of 1, which is zero radians.
Summary #
- Use the
ACOS()function to return the arccosine of a number.