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 function is: COS(x) = Length of the Adjacent Side / Length of the Hypotenuse
SQL COS Function Syntax
In SQL Server, The basic syntax of the COS Function is:
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, 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 multiple ways to use 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]
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.
SQL COS Function Example 2
In this example, We are going to calculate the Cosine value for all the records present in [Tax Amount] and [Service Grade] using COS Function.
SELECT [EnglishProductName] ,[SalesAmount] ,[TaxAmt] ,COS([TaxAmt]) AS [Tax Cosine] ,[Service Grade] AS Grade ,COS ([Service Grade]) AS [Cosine] FROM [Mathemetical Functions]
Thank You for Visiting Our Blog