The SQL LOG10 function is one of the Mathematical function which is used to calculate the base 10 logarithmic value of the given float value.
In this article we will show you, How to use this SQL Server LOG10 function with example.
SQL LOG10 Function Syntax
The basic syntax of the LOG10 Function is as shown below:
SELECT LOG10 (Float_Expression) FROM [Source]
SQL LOG10 Function Example 1
The LOG10 Function is used to calculate the logarithmic value of given float value with user 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 LOG10(@i)AS [LOG10 Result 1] -- Calculating LOG 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]
Within this LOG10 Function example query, Below lines of code is used to declare float variable and assigning the random value.
DECLARE @i float SET @i = 10
Next, we are calculating the logarithmic value of @i base 10. We also assigned new name to the result as ‘LOG10 Result 1’ using SQL ALIAS Column.
SELECT LOG10(@i)AS [LOG10 Result 1]
In the below statement, We used LOG10 function directly on the float values
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]
SQL LOG10 Function Example 2
In this example, We are going to calculate the base 10 logarithmic value of all the records present in the [DealerPrice] and [Tax Amount] using LOG10 Function.
SELECT [EnglishProductName] ,[Color] ,[StandardCost] ,[ListPrice] ,[DealerPrice] ,LOG10([DealerPrice]) AS [Dealer_Log result] ,[SalesAmount] ,[TaxAmt] ,LOG10([TaxAmt]) AS [Tax_Log result] FROM [SQL Tutorial].[dbo].[Prod Sales]
Thank You for Visiting Our Blog