EXP() Examples in SQL Server

In SQL Server, the T-SQL EXP() function is a mathematical function that returns the exponential value of the specified float expression.

You specify the float expression as an argument.

The exponent of a number is the constant e raised to the power of the number. The constant e (2.718281…), is the base of natural logarithms.

Syntax

The syntax goes like this:

EXP ( float_expression )   

Where float_expression is an expression of type float or of a type that can be implicitly converted to float.

Example 1 – Basic Usage

Here’s an example to demonstrate.

SELECT EXP(1) Result;

Result:

+------------------+
| Result           |
|------------------|
| 2.71828182845905 |
+------------------+

And with a different value:

SELECT EXP(16) Result;

Result:

+------------------+
| Result           |
|------------------|
| 8886110.52050787 |
+------------------+

Example 2 – Fractions

The argument can have a fractional component.

SELECT EXP(10.73) Result;

Result:

+------------------+
| Result           |
|------------------|
| 45706.6920264008 |
+------------------+

Example 3 – Expressions

You can also use expressions like this:

SELECT EXP(1 + 2) Result;

Result:

+------------------+
| Result           |
|------------------|
| 20.0855369231877 |
+------------------+

So using that example, the result is the same as doing this:

SELECT EXP(3) Result;

Result:

+------------------+
| Result           |
|------------------|
| 20.0855369231877 |
+------------------+

Example 4 – EXP() vs LOG()

The LOG() function is the inverse of EXP(). So we can do the following and get the same result:

SELECT 
  EXP( LOG(16)) 'Result 1', 
  LOG( EXP(16)) 'Result 2';

Result:

+------------+------------+
| Result 1   | Result 2   |
|------------+------------|
| 16         | 16         |
+------------+------------+