The SQL SIN function is one of the Mathematical Function which is used to calculate the trigonometry sine for the specified expression. The mathematical formula for this function is: SIN(x) = Length of the Opposite Side / Length of the Hypotenuse
SQL SIN Function Syntax
In SQL Server, The basic syntax of the SIN Function is:
-- SQL Server SIN Syntax SELECT SIN (Float_Expression) FROM [Source]
In this article we will show you, How to write SIN Function in SQL Server with example. For this, We are going to use the below shown data
SQL SIN Function Example 1
The SQL SIN Function is used to calculate the sine for given angle. The following query will show multiple ways to use SIN function.
DECLARE @i float SET @i = 208.45 SELECT SIN(@i)AS [SQL SINE] -- Calculating SIN directly SELECT SIN(0.24)AS [SQL SINE] -- Calculating SIN directly SELECT SIN(0)AS [SQL SINE] -- Calculating SIN directly SELECT SIN(1)AS [SQL SINE]
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 SIN function to calculate the sine value for the variable @i (It means SIN(208.45)). We also assigned new name to that result as ‘SQL SINE’ using SQL ALIAS Column.
SELECT SIN(@i)AS [SQL SINE]
In the next statements, We used the SIN Function directly on the float values.
SQL SIN Function Example 2
In this example, We are going to calculate the sine value for all the records present in [Tax Amount] and [Service grade] using SIN Function.
SELECT [EnglishProductName] ,[SalesAmount] ,[TaxAmt] ,SIN([TaxAmt]) AS [Tax Sine] ,[Service Grade] AS Grade ,SIN ([Service Grade]) AS [SIN Function] FROM [Mathemetical Functions]
Thank You for Visiting Our Blog