mysql - SQL Divide By Zero Error In SELECT Statement -
i'm brand new sql , use hand. i'm getting divide 0 error following in select statement:
sum(cast((replace(replace(replace (p.[total sales], '$', ''), '(','-'), ')','')) money)) - sum(cast((replace(replace(replace (p.[total cost], '$', ''), '(','-'), ')','')) money)) / sum(cast((replace(replace(replace (p.[total sales], '$', ''), '(','-'), ')','')) money)) new_bal
i know need use case, i'm not sure of application.
you use nullif in following:
nullif(expression1, 0)
in case be:
sum(cast((replace(replace(replace (p.[total sales], '$', ''), '(','-'), ')','')) money)) - sum(cast((replace(replace(replace (p.[total cost], '$', ''), '(','-'), ')','')) money)) / nullif(sum(cast((replace(replace(replace (p.[total sales], '$', ''), '(','-'), ')','')) money)),0) new_bal
Comments
Post a Comment