使用其他2个表中的计算更新表

司夜刺客

早上好。我想问一些问题,但在此之前,我想先解释一下我目前的状况。

我有3张桌子,它们是。

Table: Receiving

在此处输入图片说明

Table: GeneralInventory

在此处输入图片说明

最后一个是 Table: item_master_list

在此处输入图片说明

我在VB.Net中有一个可以执行ff的程序。

1.基于Table: Receiving我将选择一个RINo,我将在上面的图片中使用示例(RI00000001

2.在选择了之后RI00000001Table: Receiving我将按下按钮POST,然后这就是我的代码所做的。

-The代码将检查是否从列中的数据ItemCodeTable:Receiving具有在列中的相同数据ItemCodeTable: GeneralInventory

-Now if the Comparison is True or there's a same Data from both Tables the Column QtyPack and QtyStan from Table: Receiving will be added/SUM in the Column Qty of GeneralInventory

-Now if the Comparison is False or theres no comparison between two tables then the data will be inserted in GeneralInventory.

I hope you get it but if not here is the sample image.

在此处输入图片说明

and now my code for that procedure is this.

Code for finding.

Select * 
From 
    GeneralInventory GI 
Inner Join 
    Receiving RE on GI.ItemCode = RE.ItemCode 
Where RE.RINo = 'MyValue'

Now if the code above is true then this is the code for Updating

UPDATE GeneralInventory GI
INNER JOIN receiving RE ON GI.ItemCode = RE.ItemCode AND
GI.Qty = RE.QtyPack
SET GI.Qty = CAST(GI.Qty + RE.QtyPack + RE.QtyStan AS DECIMAL(6,2)) 
Where RE.RINo =  'MyValue'

or if it is false then this is the code for inserting.

INSERT INTO GeneralInventory(ItemCode, Qty) 
SELECT RE.ItemCode, RE.QtyPack 
FROM 
    Receiving RE LEFT JOIN 
    GeneralInventory GI ON GI.ItemCode = RE.ItemCode AND 
        GI.Qty =CAST(RE.QtyPack + Re.QtyStan AS DECIMAL(6,2)) 
WHERE RE.RINo  = 'MyValue'

Now here is my Question and My Question is related to the Item_Master_List and here it is.

我该如何实现这样的目标?首先在我将更新Table:GeneralInventory使用Table: Receiving我想要做一些计算Table: item_master_list我的意思是在我更新或插入的数据generalinventory我要加倍重视它item_masterlist

就像找到相同的值,item_master_list然后将其保存QtyperUoMreceiving之前使用使用该值的列将其相乘generalinventory

希望您能理解。

TYSM

罗恩·马修·莫雷诺
UPDATE generalinventory gi
set gi.qty = (SELECT (r.QtyPack * r.QtyperUoM + r.QtySan) 
           from receiving r, item_master_list ml
           where r.itemCode = ml.itemCode
           and   t.itemCode = gi.itemCode)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章