Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

LOG (Transact-SQL)

Applies to: 👁 Image
SQL Server 👁 Image
Azure SQL Database 👁 Image
Azure SQL Managed Instance 👁 Image
Azure Synapse Analytics 👁 Image
Analytics Platform System (PDW) 👁 Image
SQL analytics endpoint in Microsoft Fabric 👁 Image
Warehouse in Microsoft Fabric 👁 Image
SQL database in Microsoft Fabric

Returns the natural logarithm of the specified float expression in SQL Server.

👁 Image
Transact-SQL syntax conventions

Syntax

-- Syntax for SQL Server, Azure SQL Database 
 
LOG ( float_expression [, base ] ) 
-- Syntax for Azure Synapse SQL 
 
LOG ( float_expression ) 

Arguments

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

base
Optional integer argument that sets the base for the logarithm.

Applies to: SQL Server 2012 (11.x) and later

Return Types

float

Remarks

By default, LOG() returns the natural logarithm. Starting with SQL Server 2012 (11.x), you can change the base of the logarithm to another value by using the optional base parameter.

The natural logarithm is the logarithm to the base e, where e is an irrational constant approximately equal to 2.718281828.

The natural logarithm of the exponential of a number is the number itself: LOG( EXP( n ) ) = n. And the exponential of the natural logarithm of a number is the number itself: EXP( LOG( n ) ) = n.

Examples

A. Calculating the logarithm for a number.

The following example calculates the LOG for the specified float expression.

DECLARE @var FLOAT = 10; 
SELECT 'The LOG of the variable is: ' + CONVERT(VARCHAR, LOG(@var)); 
GO 

Here's the result set.

------------------------------------- 
The LOG of the variable is: 2.30259 
 
(1 row(s) affected) 

B. Calculating the logarithm of the exponent of a number.

The following example calculates the LOG for the exponent of a number.

SELECT LOG (EXP (10)); 
 

Here's the result set.

---------------------------------- 
10 
(1 row(s) affected) 

Examples: Azure Synapse Analytics and Analytics Platform System (PDW)

C. Calculating the logarithm for a number

The following example calculates the LOG for the specified float expression.

SELECT LOG(10); 

Here's the result set.

----------------` 
 
2.30

See Also

Mathematical Functions (Transact-SQL)
EXP (Transact-SQL)
LOG10 (Transact-SQL)


Feedback

Was this page helpful?

Additional resources