Subject Re: [ib-support] Re: New to Stored Procedures
Author Helen Borrie
At 05:32 AM 04-07-01 +0200, you wrote:
>Hi!
>
>thanks so much, Helen.
>
> > ..assuming that, while cycling through the entire
> > table and massaging the value of BETRAG for every row,
> > somewhere inside that FOR loop you are going to
> > do something with B?
>
>Yes, I want to round each value and store it back into the table. What's the
>fastest way to do that?
Just a simple DSQL update statement would be the fastest way to do that; but before committing yourself to this as a workaround to your precision problems, test whether your rounding calculation actually achieves what you want, e.g. does

set BETRAG=(BETRAG/100+0.5)*100

give you the desired result or just another load of precision problems?

If you want to, you could retain the value of BETRAG, add a column ROUND_BETRAG and add Before Insert and Before Update triggers to populate it as you go.

Even easier would be to change the datatype of BETRAG to a scaled numeric and avoid rounding problems altogether. You can't afford to be sloppy about scale in calculations and aggregates, though...

Another idea, if BETRAG *must* be a double, might be to add column ROUND_BETRAG as a numeric() and have your BI and BU triggers do the casting and calculation on new.BETRAG to fill/update ROUND_BETRAG...

Helen

All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________