bustercoder
Programmer
- Mar 13, 2007
- 96
Hello,
I have this percentage calc for fields in my stored proc:
[DISCOUNT %] = CAST(ROUND (SOP10100.TRDISAMT / SOP10200. XTNDPRCE * 100.0,2) AS NUMERIC (19, 2 )),
[DISC WARNING] = CASE WHEN CAST(ROUND(SOP10100 .TRDISAMT / SOP10200.XTNDPRCE * 100.0,2) AS NUMERIC (19, 2)) <> 50.00 THEN CAST(ROUND(SOP10100 .TRDISAMT / SOP10200.XTNDPRCE * 100.0,2) AS NUMERIC (19, 2)) ELSE null END
I know that I am getting the dreaded 'Divide by Zero Error' because because in some cases the SOP10100.TRDISAMT will be smaller OR larger than the SOP10200.XTNDPRCE. Can someone please show me how to handle this condition to avoid this 'Divide by Zero Error? I've researched it but I can't see how I should handle this? In other words, should I handle it through logic flow (IF/THEN) or write the calculation all together differently?
Thanks,
Buster
I have this percentage calc for fields in my stored proc:
[DISCOUNT %] = CAST(ROUND (SOP10100.TRDISAMT / SOP10200. XTNDPRCE * 100.0,2) AS NUMERIC (19, 2 )),
[DISC WARNING] = CASE WHEN CAST(ROUND(SOP10100 .TRDISAMT / SOP10200.XTNDPRCE * 100.0,2) AS NUMERIC (19, 2)) <> 50.00 THEN CAST(ROUND(SOP10100 .TRDISAMT / SOP10200.XTNDPRCE * 100.0,2) AS NUMERIC (19, 2)) ELSE null END
I know that I am getting the dreaded 'Divide by Zero Error' because because in some cases the SOP10100.TRDISAMT will be smaller OR larger than the SOP10200.XTNDPRCE. Can someone please show me how to handle this condition to avoid this 'Divide by Zero Error? I've researched it but I can't see how I should handle this? In other words, should I handle it through logic flow (IF/THEN) or write the calculation all together differently?
Thanks,
Buster