The SQL Server COS function is a Mathematical Function that calculates the trigonometry Cosine for the specified expression. The syntax of the COS Function is shown below.
SELECT COS (Float_Expression) FROM [Source]
For this COS Function demo, we use the Math Table data
SQL COS Function Example
The mathematical formula for this function is COS(x) = Length of the Adjacent Side / Length of the Hypotenuse. The COS Function calculates the Cosine for a given angle. The following query shows you multiple ways to use this COS function.
DECLARE @i float SET @i = 208.45 SELECT COS(@i)AS [SQLCosine] -- Calculating COS directly SELECT COS(0.24)AS [SQLCosine] -- Calculating COS directly SELECT COS(0)AS [SQLCosine] -- Calculating COS directly SELECT COS(1)AS [SQLCosine]
We used the COS Mathematical Function to calculate the Cosine value for the variable @i. It means COS(208.45)
SELECT COS(@i)AS [SQLCosine]
In the next SQL Server statement, we used the Cosine Function directly on the float values.
SELECT COS(0.24)AS [SQLCosine]
COS Function Example 2
In this COS Function example, we are going to calculate the Cosine value for all the records present in [Tax Amount] and [Service Grade] of the Mathematical function table.
SELECT [EnglishProductName] ,[SalesAmount] ,[TaxAmt] ,COS([TaxAmt]) AS [Tax Cosine] ,[Service Grade] AS Grade ,COS ([Service Grade]) AS [Cosine] FROM [Mathemetical Functions]