Sql error "Divide by zero error encountered" when the divisor is 0 -
this question has reply here:
how avoid “divide zero” error in sql? 14 answersi have error coming "divide 0 error encountered." in sql server 2005. understand have few rows are getting divided 0 results in error. wondering if can eliminate error when divisor zero. if divisor 0, should homecoming 0. how can that?
sum(isnull(cast(s.s_amountcollected numeric(10, 2)), 0)) / sum(isnull(cast(s.amountsold numeric(10, 2)), 0))
thank you!
use case statement:
case when sum(isnull(cast(s.amountsold numeric(10, 2)), 0) = 0 0 else sum(isnull(cast(s.s_amountcollected numeric(10, 2)), 0)) / sum(isnull(cast(s.amountsold numeric(10, 2)), 0)) end
sql
No comments:
Post a Comment