SQL COS Function

The SQL COS function is a Mathematical Function that calculates the trigonometry Cosine for the specified expression. The syntax of the SQL Server COS Function is

SELECT COS (Float_Expression)
FROM [Source]

For this COS Function demo, we use the Math Table data

SQL COS Function Example 1

The mathematical formula for this COS 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 [SQL Cosine]

-- Calculating COS directly
SELECT COS(0.24)AS [SQL Cosine]

-- Calculating COS directly
SELECT COS(0)AS [SQL Cosine]

-- Calculating COS directly
SELECT COS(1)AS [SQL Cosine]
SQL COS FUNCTION 1

We used the COS Mathematical Function to calculate the Cosine value for the variable @i. It means COS(208.45)

SELECT COS(@i)AS [SQL Cosine]

In the next SQL Server statement, we used the Cosine Function directly on the float values.

SELECT COS(0.24)AS [SQL Cosine]

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]
SQL COS FUNCTION 2