Tutorial Gateway

  • C Language
  • Java
  • R
  • SQL
  • MySQL
  • Python
  • BI Tools
    • Informatica
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • QlikView
  • Js

SQL LOG Function

by suresh

The SQL LOG function is a SQL Mathematical function which calculates the natural logarithmic value of given float value. The syntax of the SQL Server LOG Function is as shown below:

SELECT LOG (Float_Expression, base)
FROM [Source]

Base: This is an optional argument. If you omit this argument, the SQL LOG function will consider the default e as logarithm base. However, you can change the base value as per your requirement. The value of e is approximately equal to 2.71828

SQL LOG Function Example 1

The SQL Logarithmic Function is used to calculate the logarithmic value of a given number with the specified base value. In this example, We are going to check the same with different data and display the output

DECLARE @i float
SET @i = 10

SELECT LOG(@i)AS [LOG Result 1]

-- Calculating LOG directly
SELECT LOG(1) AS [LOG Result 2]

SELECT LOG(96) AS [LOG Result 3]

SELECT LOG(10.90 + 15.10 - 22.50 + 1.50) AS [LOG Result 4]

-- Calculating LOG with two arguments
SELECT LOG(10, 4) AS [LOG Result 5]

SELECT LOG((10.90 + 15.10 - 22.50 + 1.50), 8) AS [LOG Result 6]

OUTPUT

SQL LOG Function 1

ANALYSIS

Within this log function example query, we are calculating the logarithmic value of @i base e (It means LOG(10, e)).

SELECT LOG(@i)AS [LOG Result 1]

In the below statement, We used LOG function directly on the float values

SELECT LOG(1) AS [LOG Result 2]
SELECT LOG(96) AS [LOG Result 3]
SELECT LOG(10.90 + 15.10 - 22.50 + 1.50) AS [LOG Result 4]

In the next statement, We used the LOG Function with two arguments (float and base value). It means the logarithmic value of 10 bases 4.

SELECT LOG(10, 4) AS [LOG Result 5]

SQL Logarithmic Function Example 2

In this example, We are going to calculate the logarithmic value of all the records present in the [StandardCost] and [Tax Amount] using LOG Function.

SELECT [EnglishProductName]
      ,[Color]
      ,[StandardCost]
      ,LOG([StandardCost], 8) AS [Cost_Log result]
      ,[ListPrice]
      ,[DealerPrice]
      ,[SalesAmount]
      ,[TaxAmt]
      ,LOG([TaxAmt]) AS [Tax_Log result]
  FROM [SQL Tutorial].[dbo].[Prod Sales]

OUTPUT

SQL LOG Function 2

Placed Under: SQL

Trending Posts

Edit Power BI App

Python program to find ASCII Value of Total Characters in a String

Java Array

Python pow

Power BI R Script

MySQL COT Function

MySQL LPAD Function

SQL POWER Function

Python ASINH

Add Reports to Power BI Dashboard

  • C Programs
  • Java Programs
  • SQL FAQ’s
  • Python Programs
  • SSIS
  • Tableau
  • JavaScript

Copyright © 2019 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy