Subject Re: [firebird-support] Re: Query giving "Unsuccessful execution caused by system error"
Author Helen Borrie
At 06:15 AM 29/03/2005 +0000, you wrote:


>Hi Alexandre,
>
> > What the type of the involved fields ?
> >
> > If they are numeric(x,y) (or decimal) you are getting problem
>because the lot of multiplications and divisions, that is leading to
>an overflow on the decimals...
> >
> > Try casting those columns to double precision.
> >
>
>I think it's the sum equation also, but I'm sure that I'm not doing
>any illegal math (divide 0 and stuff like that).

Divide By Zero is a distinct arithmetic boo-boo that has its own
exception. But your certainty about "illegal math" is an illusion.

>It is working in the other app.

"The other app" is using fixed decimal types too? Re-read Alexandre's advice!


>The types of data are:
>
>ITRPORCCOB DECIMAL(14,4),
>ITRHON DECIMAL(14,4),
>ITRMULTHON DECIMAL(14,4),
>ITRDESCONTOTAB DECIMAL(14,4),
>ITRVLRINDXFAT DECIMAL(14,4),
>ITRMULTTAB SMALLINT
>
>as I need to work with BCD types. ITRMULTTAB is only a multiplier, so
>it's a smallint.
>
>Are my definitions of BCD right? DECIMAL(14,4)?

Scale of BCD numbers can be 1, 2, 3 or 4. If you only need 2, don't use 4.

sum
(
(
(
(
( i.ItrHon * i.ItrMultHon /* result is now a (14,8) */
* i.ItrVlrIndxFat) /* result is now a (14,12) */
* (
i.ItrPorcCob/100)) /* result is now an integer
overflow: scale moves to 16, but the precision of the number is only
14. Actually, it's possible at this point that Firebird's enforcement of
precision will "forgive" here and accommodate this number as an
(18,16). Then, it will be the next operation that blows it. */

I'll leave you to muse upon the rest...

* (1-(i.ItrDescontoTab/100)) )* i.ItrMultTab)) as
VlrFat,

If you don't have it already, pick up Geoff Worboys' white paper on number
types from www.ibobjects.com/TechInfo.html. It has helped a lot of people
(including me).

./hb