SQL COS Function

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

Source Table

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


-- Calculating COS directly
SELECT COS(0.24)AS [SQLCosine]

-- Calculating COS directly

-- Calculating COS directly
COSINE Example 1

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


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

SELECT COS(0.24)AS [SQLCosine]

SQL 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]
      ,COS([TaxAmt]) AS [Tax Cosine]
      ,[Service Grade] AS Grade
      ,COS ([Service Grade]) AS [Cosine] 
  FROM [Mathemetical Functions]

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.