The SQL ACOS function is one of the SQL Mathematical Function which is used to calculate the trigonometry Arc cosine for the specified expression. Arc-cosine is also called as inverse of a cosine, Please refer SQL COS Function article to understand the Cosine Function.
SQL ACOS Function Syntax
The basic syntax of the SQL Server ACOS Function is as shown below:
SELECT ACOS (Float_Expression) FROM [Source]
TIP: The ACOS function only accepts float values between -1 and 1.
In this article, we will show you, How to write ACOS Function in SQL Server with example. For this, We are going to use the below shown data
SQL ACOS Function Example 1
The SQL Server ACOS Function is used to calculate the Arc cosine for the given angle. The following query will show you multiple ways to use ACOS function.
DECLARE @i float SET @i = -0.80 SELECT ACOS(@i) AS [Arc Cosine] -- Calculating ACOS directly SELECT ACOS(0.27) AS [Arc Cosine] -- Calculating ACOS directly SELECT ACOS(0.25 + 0.55 - 0.77) AS [Arc Cosine]
Below lines of code is used to declare float variable and assigning the value.
DECLARE @i float SET @i = -0.80
In the below statement, We used ACOS function to calculate the Arccosine value for the variable @i (It means ACOS(-0.80)). We also assigned new name to that result as ‘Arc Cosine’ using SQL ALIAS Column.
SELECT ACOS(@i) AS [Arc Cosine]
In the next statements, We used the ACOS Function directly on the float values.
SQL ACOS Function Example 2
In this example, We are going to calculate the Arc cosine value for all the records present in [Service Grade] using ACOS Function.
SELECT [EnglishProductName] ,[Color] ,[StandardCost] ,[SalesAmount] ,[Service Grade] ,ACOS([Service Grade]) AS [Arc Cosine] FROM [Mathemetical Functions]
Thank You for Visiting Our Blog