0
@dt TVP_API_DELIVERY_ORDER READONLY
UPDATE Stkm SET
Stkm.Itm_Qty_OnHand = CASE
WHEN tvp.Flag='I' THEN (Itm_Qty_OnHand- (SELECT SUM(T1.OrderQty) FROM @dt T1 WHERE T1.ItemCode=tvp.ItemCode))
WHEN tvp.Flag='U' THEN ((Itm_Qty_OnHand+(SELECT SUM(T2.Dod_Qty) FROM DoD T2 WHERE T2.Itm_cd=tvp.ItemCode AND [email protected] AND [email protected]))-(SELECT SUM(T3.OrderQty) FROM @dt T3 WHERE T3.ItemCode=tvp.ItemCode))
WHEN tvp.Flag='D' THEN (Itm_Qty_OnHand + (SELECT SUM(T4.Dod_Qty) FROM DoD T4 WHERE T4.Itm_cd=tvp.ItemCode AND [email protected] AND [email protected]))
ELSE 0
END
FROM @dt tvp
INNER JOIN Stkm ON tvp.ItemCode=Stkm.Itm_Cd
上記のクエリを簡略化する方法。上記のクエリの実行を高速化する方法はありますか?テーブル値パラメータ(tvp)からテーブルに値を更新するSQL ServerのSelectステートメントの合計からの値の更新