I need to do a update in a certain field, where it should arrive at least until "zero" can not be negative. And when I get to zero I need it from the update of the remaining amount in the next field. "The setting is for it to drop the first amount in the record with the lower one expiring" FIFO. "
Example: I'm going to dial 9948
Unit Quantity Expira
9947 10/10/2017
9947 10/11/2017
Wrong form:
Unit Quantity Expira
-1 10/10/2017
9947 10/11/2017
Correct form:
Unit Quantity Expira
0 10/10/2017
9946 10/11/2017
Query:
UPDATE invdtl
SET untqty = untqty - 9948
WHERE prtnum = 'OP-CX44LT'
AND invsts = 'LIB'
AND lst_arecod IN ('1SUPRCK')
AND expire_dte <= TRUNC(expire_dte)