Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Divide by Zero Error on Percentage Calculation 1

Status
Not open for further replies.

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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top