SQL EXP Function

The SQL EXP function is a Mathematical function that 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 Syntax

The syntax of the SQL Server EXP Function is

SELECT EXP (Float_Expression)
FROM [Source]

SQL Server EXP Function Example

The EXP Function is useful 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]
SQL EXP Function 1

Below are lines of code that help to declare float variables and assign random values.

DECLARE @i float
SET @i = 2

Next, we are calculating the exponential value of @i. We also assigned a new name to the result as ‘Exponent Result 1’ using ALIAS Column In SQL Server.

SELECT EXP(@i)AS [Exponent Result 1]

In the below statement, We used the 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 the SQL 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 all the records present in the [Tax Amount] column using the EXP Function.

SELECT [EnglishProductName]
      ,[Color]
      ,[StandardCost]
      ,[ListPrice]
      ,[DealerPrice]
      ,[SalesAmount]
      ,[TaxAmt]
      ,EXP([TaxAmt]) AS [Tax_Exponent result]
  FROM [Prod Sales]
SQL EXP Function 2
Categories SQL