हाँ। आप इसे एक ही UPDATE - FROM
. के साथ कर सकते हैं आपके BULK INSERT
. के बाद स्टेटमेंट :
UPDATE t3 SET initialValue = t.mySum
FROM test3 t3
CROSS APPLY (SELECT SUM(
CASE t3.v1 WHEN 'M170_2' THEN CASE d.M170_2
WHEN 1 THEN 1
WHEN 2 THEN .75
WHEN 3 THEN .25
WHEN 4 THEN .1
ELSE 1 END END *
CASE t3.v1 WHEN 'M170_3' THEN CASE d.M170_3
WHEN 1 THEN 1
WHEN 2 THEN .75
WHEN 3 THEN .25
WHEN 4 THEN .1
ELSE 1 END END *
CASE t3.v1 WHEN 'M170_4' THEN CASE d.M170_4
WHEN 1 THEN 1
WHEN 2 THEN .75
WHEN 3 THEN .25
WHEN 4 THEN .1
ELSE 1 END END *
d.RESP_WEIGHT / 4898.947426) as mySum
FROM my_data_db d WHERE d.combo = t3.combo) t
WHERE t3.v1 IS NOT NULL OR t3.v2 IS NOT NULL OR t3.v3 IS NOT NULL
अपने ट्रिगर से ऐसा करने के लिए, आपको एक मामूली बदलाव की आवश्यकता है:
UPDATE t3 SET initialValue = t.mySum
FROM test3 t3
-- Here's the change
INNER JOIN inserted i ON i.RowID = t3.RowID
CROSS APPLY (SELECT SUM(
CASE t3.v1 WHEN 'M170_2' THEN CASE d.M170_2
WHEN 1 THEN 1
WHEN 2 THEN .75
WHEN 3 THEN .25
WHEN 4 THEN .1
ELSE 1 END END *
CASE t3.v1 WHEN 'M170_3' THEN CASE d.M170_3
WHEN 1 THEN 1
WHEN 2 THEN .75
WHEN 3 THEN .25
WHEN 4 THEN .1
ELSE 1 END END *
CASE t3.v1 WHEN 'M170_4' THEN CASE d.M170_4
WHEN 1 THEN 1
WHEN 2 THEN .75
WHEN 3 THEN .25
WHEN 4 THEN .1
ELSE 1 END END *
d.RESP_WEIGHT / 4898.947426) as mySum
FROM my_data_db d WHERE d.combo = t3.combo) t
WHERE t3.v1 IS NOT NULL OR t3.v2 IS NOT NULL OR t3.v3 IS NOT NULL