Menu

SQL Server LOG() Function

Updated on

LOG() returns the logarithm of a float expression as a float. By default, it returns the natural logarithm (base e); on SQL Server 2012 (11.x) and later, the optional second argument selects another integer base. See Microsoft’s LOG() reference.

Syntax

LOG(float_expression [ , base ])
  • float_expression: a float expression or a type that SQL Server can implicitly convert to float.
  • base: an optional integer logarithm base. If omitted, the base is e.

Azure Synapse SQL supports only the one-argument form LOG(float_expression).

Examples

Calculate a natural logarithm and a base-10 logarithm:

SELECT LOG(10) AS natural_log,
       LOG(100, 10) AS base_10_log;
natural_log base_10_log
2.30258509299405 2.0

Use LOG10() for the base-10 logarithm when no other base is needed. For the inverse exponential operation, see EXP().

Conclusion

Use LOG() for the natural logarithm by default, or pass a base on SQL Server 2012 and later when the calculation requires a different logarithm base.