× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Would it help to multiply one of the fields by 100 before the division instead of multiplying after the division?

On 3/17/2013 7:24 PM, Sam_L wrote:
Boss was trying to sum two decimal fields and get the percentage of the
sums. It looked easy, but the percentage always came out as zero.

I did some experimentation and here's a simulation that anyone can run:

select sum(CDTDUE) CDTDUE, sum(BALDUE) BALDUE,
(sum(CDTDUE) / sum(BALDUE)) *100 pct
from qiws/QCUSTCDT

The first two sum statements clearly show that the fields are numeric
with 2 decimal places.

The PCT field is zero, because it apparently is resulting as an integer.

If I force the first sum in the division to be decimal, like this:

select sum(CDTDUE) CDTDUE, sum(BALDUE) BALDUE,
(decimal(sum(CDTDUE),11,2) / sum(BALDUE)) *100 pct
from qiws/QCUSTCDT

then pct comes out to 2.29787594861576292000.

If I instead force the second sum in the division to decimal, like this:

select sum(CDTDUE) CDTDUE, sum(BALDUE) BALDUE,
(sum(CDTDUE) / decimal(sum(BALDUE),11,2) ) *100 pct
from qiws/QCUSTCDT

then pct comes out as zero, again apparently an integer.

So, apparently we are missing something in the SQL rules of arithmetic.
Does anyone know what?

Thanks, Sam

On V7R1, cume from around October. But I see the same results on V5R3.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.