I want to write this query (all of the fields are int):
select SUM(Service.discount+((Service.price*Factor.discount)/(Factor.amount-Factor.discount)))
But sometimes I get this error:
Arithmetic overflow error converting expression to data type int.
Other times I get this error:
Divide by zero error encountered.
How can I rewrite this query to avoid these errors?
//I Use this but agan overflow
select case when(Factor.amount-Factor.discount)<>0 then
Service.discount+((Service.price*Factor.discount)/(Factor.amount-Factor.discount))
else
Service.discount
end
from Factor inner join Service on Factor.code=Service.factorCode