The SQL EXP function is a SQL Mathematical function which is used to return E raised to the power of the given float value, Where E is Euler’s number and it is approximately equal to 2.71828.
For example, if we specify the expression as, EXP (2). It means e² ==> 2.718² ==> 7.38.
SQL EXP Function Syntax
The syntax of the SQL Server EXP Function is
SELECT EXP (Float_Expression) FROM [Source]
SQL EXP Function Example 1
The SQL server EXP Function is used to calculate the power of Euler’s number E. In this example, We are going to check the same with different data (both positive and negative values) and display the output
DECLARE @i float SET @i = 2 SELECT EXP(@i)AS [Exponent Result 1] -- Calculating Exp directly SELECT EXP(1) AS [Exponent Result 2] SELECT EXP(62.9876) AS [Exponent Result 3] SELECT EXP(108.65 + 231.1237 - 213.32 + 15.09) AS [Exponent Result 4] -- Calculating Exp for Negative Values SELECT EXP(-1) AS [Exponent Result 5] SELECT EXP(-6.579) AS [Exponent Result 6]
OUTPUT
ANALYSIS
Below lines of code is used to declare float variable and assigning the random value.
DECLARE @i float SET @i = 2
Next, we are calculating the exponential value of @i. We also assigned new name to the result as ‘Exponent Result 1’ using SQL ALIAS Column I nSQL Server.
SELECT EXP(@i)AS [Exponent Result 1]
In the below statement, We used EXP function directly on the positive float values. Here, EXP(1) means e1 ==> 2.7181 ==> 2.718
SELECT EXP(1) AS [Exponent Result 2] SELECT EXP(62.9876) AS [Exponent Result 3] SELECT EXP(108.65 + 231.1237 - 213.32 + 15.09) AS [Exponent Result 4]
Next, We used EXP function directly on the negative float values
SELECT EXP(-1) AS [Exponent Result 5] SELECT EXP(-6.579) AS [Exponent Result 6]
SQL Exponent Function Example 2
In this Mathematical function example, We are going to calculate the E raised to the power of the all the records present in the [Tax Amount] column using EXP Function.
SELECT [EnglishProductName] ,[Color] ,[StandardCost] ,[ListPrice] ,[DealerPrice] ,[SalesAmount] ,[TaxAmt] ,EXP([TaxAmt]) AS [Tax_Exponent result] FROM [SQL Tutorial].[dbo].[Prod Sales]
OUTPUT