2
I have an appointment that makes a calculation, plus the field "a. totalcustoproducts" appears with zero value in a few moments, then generates a division error by zero, is it possible to pass some standard value? Type 1 if zero?
select a.totalcustoprodutos, a.datanota, a.numeronota, a.cfop,
((a.totalnota / a.totalcustoprodutos) - 1.000) * 100 as TotalMargem
from TB_C_VENDAS a
where a.numeronota > 0 and a.tipooperacao = 'V'
And the correct assume the value of
a.totalnotafilled if it has no value (0) ina.totalcustoprodutos? The logic is this you want, or are just trying to solve one problem causing another?– Maniero
I need the total cost product products to find the average, I can not use the totalnote. I thank you!
– Harry
So the answers given don’t do what you want, right? What should be done then when you find a zero in the
a.totalcustoprodutos? Nothing. does not calculate? Generates error? Takes another value? Uses a completely different formula?– Maniero
Already posted an answer that solved the problem. thank you!
– Harry
If what you said above is right this answer only solves some situations. But I am not the one who will have loss. If you really answer, what you have commented is wrong. Without knowing the real problem, I doubt it will solve correctly. And the problem may be somewhere else. Maybe there shouldn’t even be 0 there. But there is already speculation.
– Maniero
You are right, it does not solve everything, it is necessary to analyze the report after more is the only way not to have the error message. I have already identified why the total cost products = 0 plus I need to bring all the records, so it would be a way to avoid the initial error, after the report then it is possible to analyze why the cost is zero. Thanks
– Harry