The SQL Server ACOS function calculates the trigonometry Arc cosine for the specified expression. The Arc cosine is also called the inverse of a COSINE Function, and the syntax of SQL ACOS is
SELECT ACOS (Float_Expression) FROM [Source]
TIP: The ACOS function only accepts float values between -1 and 1 and for this demo, we use the Math Table data.
SQL ACOS Function Example
The ACOS Function calculates the Arc cosine for the given angle. The following SQL Server query will show you multiple ways to use the Arc COSINE function.
DECLARE @i float SET @i = -0.80 SELECT ACOS(@i) AS [Arc Cosine] -- Calculating directly SELECT ACOS(0.27) AS [Arc Cosine] -- Calculating directly SELECT ACOS(0.25 + 0.55 - 0.77) AS [Arc Cosine]
We used the ACOS function to calculate the Arccosine value for the variable @i. It means ACOS(-0.80)) and assigned a new name, ‘Arc Cosine’, using ALIAS.
SELECT ACOS(@i) AS [Arc Cosine]
Example 2
We calculate the Arc cosine value for all the records present in [Service Grade] using the ACOS Mathematical Function.
SELECT [EnglishProductName] ,[Color] ,[StandardCost] ,[SalesAmount] ,[Service Grade] ,ACOS([Service Grade]) AS [Arc Cosine] FROM [Mathemetical Functions]