The SQL COS function is one of the Mathematical Function which is used to calculate the trigonometry Cosine for the specified expression.

The mathematical formula for this COS function is: COS(x) = Length of the Adjacent Side / Length of the Hypotenuse

## SQL COS Function Syntax

The basic syntax of the SQL Server COS Function is as shown below:

SELECT COS (Float_Expression) FROM [Source]

In this article, we will show you, How to write COS Function in SQL Server with example. For this demonstration, We are going to use the below shown data

## SQL COS Function Example 1

The SQL server COS Function is used to calculate the Cosine for given angle.

The following query will show you the multiple ways to use this COS function.

**T-SQL CODE**

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]

**OUTPUT**

**ANALYSIS**

Within this Cos function example query, Below lines of code is used to declare float variable and assigning the value.

DECLARE @i float SET @i = 208.45

In the below statement, We used COS function to calculate the Cosine value for the variable @i (It means COS(208.45)).

We also assigned new name to that result as ‘SQL Cosine’ using SQL ALIAS Column.

SELECT COS(@i)AS [SQL Cosine]

In the next statements, We used the COS Function directly on the float values.

SELECT COS(0.24)AS [SQL Cosine]

## Sql Server 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.

**T-SQL CODE**

SELECT [EnglishProductName] ,[SalesAmount] ,[TaxAmt] ,COS([TaxAmt]) AS [Tax Cosine] ,[Service Grade] AS Grade ,COS ([Service Grade]) AS [Cosine] FROM [Mathemetical Functions]

**OUTPUT**

Thank You for Visiting Our Blog