SQL EXP Function

The SQL Server 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.

The syntax of the EXP Function is as shown below.

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 the ALIAS Column In SQL Server. Please refer to the list of SQL Server Mathematical functions from our SQL tutorial page.

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

In the statement below, we used the EXP function directly on the positive float values. Here, EXP(1) means e1 ==> 2.7181 ==> 2.718. Refer to the SELECT Statement in SQL Server.

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 SELECT query, 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. Please refer to the SQL LOG and SQL SQUARE functions from the list of Mathematical functions.

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

What is the difference between POWER and EXP in SQL?

Both POWER and EXP are mathematical functions that calculate the exponential of the given number, but they work differently.

EXP

The EXP function calculates the exponential value of the given number. However, the base value is fixed as e ~= 2.71828. This means you have the option to choose the exponent value and no control over the base because it is fixed to e.

For example, SELECT EXP(5) = (2.71828)5 = 148.413.

POWER:

The SQL POWER function accepts the base and exponent values as arguments. Next, it finds the base raised to the power of the exponent. If the goal is to choose the base and exponent values, especially to calculate the exponential value of different bases, choose the POWER() function.

For example, SELECT POWER(10, 2) = 102 = 100.

How to use SQL EXP to calculate exponential growth?

To calculate exponential growth, we can use the POWER or EXP functions. The mathematical formula to calculate the exponential growth of continuous sales is

Predicted_Value = Initial_Value * e(growth rate * times)

In the following query, we will calculate the exponential growth of product sales by color. Here, we grouped sales by color and used the mathematical formula to predict the future value. To keep the decimal precision to 2, we used the ROUND function; otherwise, you can remove it.

SELECT [Color]
,SUM([SalesAmount]) AS CurrentSales
,0.12 AS GrowthRate
,3 As Year
,ROUND(SUM(SalesAmount) * EXP(0.12 * 3), 2) AS ProjectedSales
FROM [dbo].[Mathematical Functions]
GROUP BY Color
Color	CurrentSales	GrowthRate	Year	ProjectedSales
Black	12006.4464	0.12	3	17209.19
Blue	5587.3682	0.12	3	8008.54
NA	2009.09	0.12	3	2879.69
Yellow	699.0982	0.12	3	1002.04
Categories SQL