Skip to content

Latest commit

 

History

History
128 lines (93 loc) · 3.94 KB

File metadata and controls

128 lines (93 loc) · 3.94 KB

title: "LOG (Transact-SQL) | Microsoft Docs" ms.custom: "" ms.date: "07/29/2017" ms.prod: sql ms.prod_service: "database-engine, sql-database, sql-data-warehouse, pdw" ms.component: "t-sql|functions" ms.reviewer: "" ms.suite: "sql" ms.technology: t-sql ms.tgt_pltfrm: "" ms.topic: "language-reference" f1_keywords:

  • "LOG"
  • "LOG_TSQL" dev_langs:
  • "TSQL" helpviewer_keywords:
  • "float expressions"
  • "logarithm of expression"
  • "LOG function" ms.assetid: f7c39511-cd84-4362-93ba-0d93655217ee caps.latest.revision: 42 author: edmacauley ms.author: edmaca manager: craigg monikerRange: ">= aps-pdw-2016 || = azuresqldb-current || = azure-sqldw-latest || >= sql-server-2016 || = sqlallproducts-allversions"

LOG (Transact-SQL)

[!INCLUDEtsql-appliesto-ss2008-all-md]

Returns the natural logarithm of the specified float expression in [!INCLUDEssNoVersion].

Topic link icon Transact-SQL Syntax Conventions

Syntax

-- Syntax for SQL Server  
  
LOG ( float_expression [, base ] )  
-- Syntax for Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse  
  
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: [!INCLUDEssSQL11] through [!INCLUDEssCurrent]

Return Types

float

Remarks

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.

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  

[!INCLUDEssResult]

-------------------------------------  
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));  
  

[!INCLUDEssResult]

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

Examples: [!INCLUDEssSDWfull] and [!INCLUDEssPDW]

C. Calculating the logarithm for a number

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

SELECT LOG(10);  

[!INCLUDEssResult]

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

See Also

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