PIテーブルから選択されたLCID、LCNo、AmendmentStatusの3つの列を更新したいので、正常に実行される次の更新クエリを記述します。
UPDATE #TempTableOne
SET
LCID=(SELECT ISNULL(ExportLCID,0) FROM ExportLC WHERE ExportLCID= (SELECT LCID FROM [PI] WHERE PIID=(SELECT PIID FROM Job WHERE JobID=TT.OrderID))),
LCNo=(SELECT ISNULL(ExportLCNo,'') FROM ExportLC WHERE ExportLCID= (SELECT LCID FROM [PI] WHERE PIID=(SELECT PIID FROM Job WHERE JobID=TT.OrderID))),
AmendmentStatus=(SELECT AmendmentStatus FROM ExportLC WHERE ExportLCID= (SELECT LCID FROM [PI] WHERE PIID=(SELECT PIID FROM Job WHERE JobID=TT.OrderID))),
FROM #TempTableOne AS TT
WHERE TT.OrderType=3
しかし、更新クエリが次のような単一のクエリを実行することは可能ですか?
Update #TempTableOne
SET SELECT LCID = ISNULL(ExportLCID,0) ,
LCNo=ISNULL(ExportLCNo,''),
AmendmentStatus=AmendmentStatus
FROM ExportLC
WHERE ExportLCID = (SELECT LCID
FROM [PI]
WHERE PIID=(SELECT PIID
FROM Job
WHERE JobID=TT.OrderID
)
)
)
クエリを高速化したいので