2010-12-02 77 views
0

我在加入時非常虛弱,我需要知道如何使用連接轉換以下查詢。此查詢與子查詢工作正常,但我需要將其轉換並使用它進行連接。如何在UPDATE查詢中使用JOIN

update dbo.TFIN_Stmt_Line_Item_Dtl 
set Stmt_Line_Item_Dtl_Desc='Changes from Baseline' 
where Stmt_Line_Item_Dtl_Desc='Increased Hours' 
and Stmt_Line_Item_Id 
in (select tmt_Line_Item_Ref_Id 
    from dbo.TFIN_Stmt_Line_Item 
    where Stmt_Line_Item_Type_Id = 
     (select Stmt_Line_Item_Type_Id 
     from dbo.TFIN_Stmt_Line_Item_Type 
     where Stmt_Line_Item_Desc like 'ABOX/RBOX Amendment 18 and 20')) 

請如果有任何機構可以幫助我。

謝謝

+0

可你英語你的標題請 – 2010-12-02 09:47:26

回答

3

以下查詢使用連接更新您的表,但如果它會更快仍有待觀察。

你能發佈查詢計劃,所以我們可以看看那個

update dbo.TFIN_Stmt_Line_Item_Dtl 
set  Stmt_Line_Item_Dtl_Desc = 'Changes from Baseline' 
from dbo.TFIN_Stmt_Line_Item_Dtl dtl 
     inner join dbo.TFIN_Stmt_Line_Item li on li.tmt_Line_Item_Ref_Id = dtl.Stmt_Line_Item_Id 
     inner join dbo.TFIN_Stmt_Line_Item_Type lit on lit.Stmt_Line_Item_Type_Id = li.Stmt_Line_Item_Type_Id 
where dtl.Stmt_Line_Item_Dtl_Desc='Increased Hours' 
     and lit.Stmt_Line_Item_Desc like 'ABOX/RBOX Amendment 18 and 20' 
1
update dbo.TFIN_Stmt_Line_Item_Dtl 
set Stmt_Line_Item_Dtl_Desc='Changes from Baseline' 
where Stmt_Line_Item_Dtl_Desc='Increased Hours' 
and Stmt_Line_Item_Id 
in (select tmt_Line_Item_Ref_Id 
    from dbo.TFIN_Stmt_Line_Item Item 
    JOIN dbo.TFIN_Stmt_Line_Item_Type Type 
    on Type.Stmt_Line_Item_Type_Id = Item.Stmt_Line_Item_Type_Id 
    and Type.Stmt_Line_Item_Desc like 'ABOX/RBOX Amendment 18 and 20') 

update dbo.TFIN_Stmt_Line_Item_Dtl 
set Stmt_Line_Item_Dtl_Desc = 'Changes from Baseline' 
from dbo.TFIN_Stmt_Line_Item_Dtl Detail 
JOIN dbo.TFIN_Stmt_Line_Item Item 
on Item.tmt_Line_Item_Ref_Id = Detail.Stmt_Line_Item_Id 
JOIN dbo.TFIN_Stmt_Line_Item_Type Type 
on Type.Stmt_Line_Item_Type_Id = Item.Stmt_Line_Item_Type_Id 
and Type.Stmt_Line_Item_Desc like 'ABOX/RBOX Amendment 18 and 20') 
where Detail.Stmt_Line_Item_Dtl_Desc = 'Increased Hours' 
相關問題