Subject Re: [ib-support] arithmetic exception, numeric overflow and string truncation
Author Ivan Prenosil
> yes my QTYONHAND value is 0.0000
>
> but before i do the divide operation i am adding QTYONHAND to 23.000 , there
> is (23.0+ qtyonhand).
> is this also gives the divide by zero exception.

Unfortunately Firebird's implemetation of UPDATE statement does not
fully comply to SQL standard. The parts of SET clause are not evaluated
all at once, but from left to right.

So with the command:

Update IVITEMLOC set
QTYONHAND=QTYONHAND+-23.0,
averagecost = (((23.00000000) +(qtyonhand * averagecost)) / (23.0+qtyonhand))
where ivitemid ='RBDPOLN' and ivlocid =1

the server first evaluate
QTYONHAND=QTYONHAND+-23.0,
i.e.
QTYONHAND = 0 + -23.0
i.e.
QTYONHAND = -23.0
and then
averagecost = (((23.00000000) +(qtyonhand * averagecost)) / (23.0+qtyonhand))
i.e.
averagecost = (((23.00000000) +(qtyonhand * averagecost)) / (23.0 + -23.0))
i.e.
averagecost = (((23.00000000) +(qtyonhand * averagecost)) / (0)) <<<<<


Ivan
http://www.volny.cz/iprenosil/interbase



> > > the query that i am getting exception is
> > >
> > > Update IVITEMLOC
> > > set QTYONHAND=QTYONHAND+-23.0,
> > > averagecost = (((23.00000000) +(qtyonhand * averagecost)) / (23.0+
> > > qtyonhand))
> > > where ivitemid ='RBDPOLN' and ivlocid =1
> >
> > Perhaps your QTYONHAND in the table is zero, which lead to dividing by
> zero:
> >
> > > set QTYONHAND= 0 + -23.0,
> > > averagecost = (((23.00000000) +(qtyonhand * averagecost)) / (23.0 -
> 23.0))