SQL LOG10 Function

The SQL Server LOG10 function is a Mathematical function that calculates the base 10 logarithmic value of the given float value or expression.

The syntax of the LOG10() function is shown below.

SELECT LOG10 (Float_Expression)
FROM [Source]

TIP: The LOG10 and POWER functions are inversely related to one another.

SQL Server LOG10 Function Example

The LOG10 Function is useful to calculate the logarithmic value of a given float value with the user-specified base value. In this SQL SELECT query, we are going to check the same with different data and display the output.

DECLARE @i float
SET @i = 10

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

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

SELECT LOG10(62.9876) AS [LOG Result 3]

SELECT LOG10(120.85 + 213.17 - 220.50 + 15.09) AS [LOG10 Result 4]
LOG10 Example 1

Within this LOG10 Function example query, we are calculating the logarithmic value of @i base 10. Next, we used the function directly on the SQL Server float values. Please refer to the list of SQL Mathematical functions from our SQL Server tutorial page.

Using the LOG10() function with zero and negative numbers

If we use the LOG10() function on zero or a negative number, it returns an error: An invalid floating-point operation occurred.

SELECT LOG10(0) AS Res
Msg 3623, Level 16, State 1, Line 1
An invalid floating point operation occurred.

Use LOG10 function on table columns

In the following SELECT query, we will calculate the base 10 logarithmic value of all the records present in the [DealerPrice] and [Tax Amount] using the math LOG10 function.

Please refer to the SQL LOG (natural logarithm), SQL EXP, and SQL POWER functions from the list of available Mathematical functions.

SELECT [EnglishProductName]
      ,[Color]
      ,[StandardCost]
      ,[ListPrice]
      ,[DealerPrice]
      ,LOG10([DealerPrice]) AS [Dealer_Log result]
      ,[SalesAmount]
      ,[TaxAmt]
      ,LOG10([TaxAmt]) AS [Tax_Log result]
  FROM [Prod Sales]
LOG10 Function 2
Categories SQL