|
如果用VBA可以一条一条的赋值,如用查询,我看你的"OHND_QTY"库存量好象一个物料都是一样的,如"SHIP_DATE"会一定不一样,可用其区分先后顺序,不然最后另加一行自动ID,因为ACCESS没有数据存放的先后顺序的概念.
在查询中可参照这样的语句:
ATp1: IIf(([OHND_QTY]-DSum("[QUANTITY]","[tblA]","[COMP_WC]='" & [COMP_WC] & "' and [SHIP_DATE] <=#" & [SHIP_DATE] & "#"))<0,-[QUANTITY],[OHND_QTY]-DSum("[QUANTITY]","[tblA]","[COMP_WC]='" & [COMP_WC] & "' and [SHIP_DATE] <=#" & [SHIP_DATE] & "#"))
由于你的每一品种的[SHIP_DATE] 不是唯一的,另加一个ID用以区别先后顺序.
SELECT tblA.*, IIf(([OHND_QTY]-DSum("[QUANTITY]","[tblA]","[COMP_WC]='" & [COMP_WC] & "' and [ID] <=" & [ID] & ""))<0,-[QUANTITY],[OHND_QTY]-DSum("[QUANTITY]","[tblA]","[COMP_WC]='" & [COMP_WC] & "' and [ID] <=" & [ID] & "")) AS ATp1
FROM tblA; |
|