Question:
How can I have a Query’s Log10 function be executed only in rows different from 0 (zero), leaving rows equal to zero with value 0 (zero)?
Solution:
To apply Log10 function only to rows that are different from 0 (zero), you must use Case/Else commands inside an SQL query in order to test their values before you run the function. If the value is zero, the same value will be attributed to the field. If the value is different from zero, Log10 function will be applied.
Example of SQL query performing this:
SELECT CASE WHEN Field = 0 THEN 0 ELSE LOG10(Field) END AS Logarithm
FROM table
FROM table
NOTE: This code is only valid for SQLServer databases.