| title | LOG (Transact-SQL) | |||
|---|---|---|---|---|
| description | LOG (Transact-SQL) | |||
| author | markingmyname | |||
| ms.author | maghan | |||
| ms.date | 07/29/2017 | |||
| ms.service | sql | |||
| ms.subservice | t-sql | |||
| ms.topic | reference | |||
| ms.custom |
|
|||
| f1_keywords |
|
|||
| helpviewer_keywords |
|
|||
| dev_langs |
|
|||
| monikerRange | >=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric || =fabric-sqldb |
[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw-fabricsqldb]
Returns the natural logarithm of the specified float expression in [!INCLUDEssNoVersion].
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
-- Syntax for SQL Server, Azure SQL Database
LOG ( float_expression [, base ] )
-- Syntax for Azure Synapse SQL
LOG ( float_expression )
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: [!INCLUDEssSQL11] and later
float
By default, LOG() returns the natural logarithm. Starting with [!INCLUDEssSQL11], 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.
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 [!INCLUDEssResult]
-------------------------------------
The LOG of the variable is: 2.30259
(1 row(s) affected)
The following example calculates the LOG for the exponent of a number.
SELECT LOG (EXP (10));
[!INCLUDEssResult]
----------------------------------
10
(1 row(s) affected)
Examples: [!INCLUDEssazuresynapse-md] and [!INCLUDEssPDW]
The following example calculates the LOG for the specified float expression.
SELECT LOG(10); [!INCLUDEssResult]
----------------`
2.30
Mathematical Functions (Transact-SQL)
EXP (Transact-SQL)
LOG10 (Transact-SQL)