Problem solve Get help with specific problems with your technologies, process and projects.

Avoid "divide by zero" in query and SQL

Here's a simple workaround to avoid the "divide by zero" error.

Many times when doing mass updates or query reports, you run into situations where a "divide by zero" error occurs. Sure, you can put all sorts of error trapping and the like, but there may be conditions where the value you are using to divide is zero. I add a miniscule value to my field that may be zero.

(profit/(prfinv+.0001) ) *100

It doesn't affect the calculation (at least with the decimal precision I'm working with) and protects me from program crashes. The same method can be applied when using a calculated value in SQL.


The Best Web Links: tips, tutorials and more.

Visit the ITKnowledge Exchange and get answers to your developing questions fast.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.

Dig Deeper on Windows on iSeries