[英]How to Update a numeric field with the SUM of the numeric field in a different table MS-ACCESS 13
I have a supply inventory database with 3 tables.我有一个包含 3 个表的供应库存数据库。 Main (Warehouse Stock), Supply Issue Table, and Supply Purchases Table.主要(仓库库存)、供应问题表和供应采购表。 All three tables share the relationship ITEM #.所有三个表共享关系 ITEM #。 Supply Issue and Supply Purchases both log transactions (ie Item #, Quantity Issued or purchased). Supply Issue 和 Supply Purchases 都记录交易(即项目编号、发出或购买的数量)。 I need to have the Purchase and Issue tables update the total quantity in the Main Table我需要让采购和发行表更新主表中的总数量
I created an update query to update the two fields in the main table(PQuantity/IQuantity).我创建了一个更新查询来更新主表(PQuantity/IQuantity)中的两个字段。 Then a third auto-calculated field (MQuantity) which is (PQuantity-IQuantity).然后是第三个自动计算字段 (MQuantity),即 (PQuantity-IQuantity)。 I did it this way because I understood I couldn't run an update query for an auto-calculated field?我这样做是因为我知道我无法对自动计算的字段运行更新查询?
Here's the update query SQL for purchases:这是购买的更新查询 SQL:
UPDATE [MAIN (WAREHOUSE STOCK)]
INNER JOIN [Supply Purchases Table]
ON [MAIN (WAREHOUSE STOCK)].[ITEM #] = [Supply Purchases Table].[ITEM #]
SET [MAIN (WAREHOUSE STOCK)].PQUANTITY = +[Supply Purchases Table]![QTY ADDED];
Here's the update query SQL for issues:这是问题的更新查询 SQL:
UPDATE [MAIN (WAREHOUSE STOCK)]
INNER JOIN [Supply Issue Table]
ON [MAIN (WAREHOUSE STOCK)].[ITEM #] = [Supply Issue Table].[ITEM #]
SET [MAIN (WAREHOUSE STOCK)].IQUANTITY = +[Supply Issue Table]![QTY ISSUED];
The problem with this is it will only total the last purchase or issue that was input.这样做的问题是它只会总计输入的最后一次购买或问题。 I also get "Type conversion" errors.我也收到“类型转换”错误。
Am I making this too difficult?我让这太难了吗?
Thanks!谢谢!
You have to add QTY ADDED
to the old value of PQUANTITY
like:您必须将QTY ADDED
到PQUANTITY
的旧值中,例如:
UPDATE
[MAIN (WAREHOUSE STOCK)]
INNER JOIN
[Supply Purchases TABLE]
ON
[MAIN (WAREHOUSE STOCK)].[ITEM #] = [Supply Purchases TABLE].[ITEM #]
SET [MAIN (WAREHOUSE STOCK)].PQUANTITY = [MAIN (WAREHOUSE STOCK)].PQUANTITY + [Supply Purchases TABLE]![QTY ADDED];
But you should rethink you data structure, as usuallay you have only one table for transactions (IN/OUT) and compute the actual stock when needed.但是你应该重新考虑你的数据结构,像往常一样,你只有一张交易表(进/出),并在需要时计算实际库存。 See Ms Featured Access Templates Inventory and Allen Browne AppInventory for some hints.有关一些提示,请参阅Ms Featured Access Templates Inventory和Allen Browne AppInventory 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.