AS400 Query – div by zero

390 pts.
Tags:
AS/400 administration
AS/400 queries
AS/400 Query
Hi I have a query as follows:- I want to define the following:-

Field       Column                                 Heading     Len     Dec

PERCENT (t01.amtdol/t02.pvsddl)*100

When I run the query it displays the above field but it converts the percent to +++++++ if the result is zero

I need to write this to a database but obviously it won't because it tries to div by 0.

 Please help

 Devan

ASKED: February 8, 2011  9:59 AM
UPDATED: February 11, 2011  1:44 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

The only way I have been able to avoid dividing by zero is to create two queries, one which does not select the zero divisor and one that does. the one that selects the zero divisor records, has a result field defined to contain a default value that keeps the output records the same. The results of the second query are added to the file member created by the first query.

I will be interested to see if someone has a better answer for you.

You can get a result in the field ‘PERCENT’ to add a value to field ‘pvsddl’
You’ve to make result field PERCENT more characters.

PERCENT (t01.amtdol/t02.pvsddl)*100

PERCENT (t01.amtdol/(t02.pvsddl+0,0001))*100

(for example)

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    What query product are you using? First, you might need to decide what "percentage" you want to see when (t02.pvsddl=0). One fairly common change to your formula might be something like {(t01.amtdol/(t02.pvsddl+.00001))*100 }. Depending on how many fractional positions you are calculating to, you might use {.001}, {.0000001} or other values to adjust. Rounding can sometimes remove the effect of such an adjustment. How you handle the zero value can depend on which product you are using. Easiest product would probably be Query Manager. Worst is probably trying to use Query for iSeries (or Query/400). Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following