Subject Problem with udf in triggers
Author Marco Lauria
Hello I noticed this problem.
I do this query in DSQL
SELECT FLOOR((SUM(IMPONIBILE)*100.0)+0.5)/100.0,
FLOOR((SUM(IVA)*100.0)+0.5)/100.0,
FLOOR((SUM(TOTALE)*100.0)+0.5)/100.0
FROM DOCUMENTI_RIGHE
INTO :tot_imp, :tot_iva, :tot_tot;

IMPONIBILE, IVA and TOTALE are fields declared as NUMERIC(18,4)

in DSQL I obtain correct results.

I do this in a trigger, I get wrong results...
then I do this:
SELECT SUM(imponibile), SUM(iva), SUM(totale) FROM DOCUMENTI_RIGHE
WHERE ID_DOCUMENTI = new.ID_DOCUMENTI
/* SELECT FLOOR((SUM(IMPONIBILE)*100.0)+0.5)/100.0,
FLOOR((SUM(IVA)*100.0)+0.5)/100.0,
FLOOR((SUM(TOTALE)*100.0)+0.5)/100.0
FROM DOCUMENTI_RIGHE*/
INTO :tot_imp, :tot_iva, :tot_tot;
tot_imp = FLOOR((tot_imp*100.0)+0.5)/100.0;
tot_iva = floor((tot_iva*100.0)+0.5)/100.0;
tot_tot = floor((tot_tot*100.0)+0.5)/100.0;

in this manner I obtain correct results.

Obviously the tot_imp, tot_iva and tot_tot are NUMERIC(18,4)

Can u explain me why this can happen?
I use firebird RC2 under W2K Server.
Regards
Marco