开发者

How to use JOIN in UPDATE query

I am very weak at join and i need to know that how can i convert following query using joins. This Query is working fine with sub queries but i need to convert it and use it making joins.

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_Typ开发者_开发知识库e_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'))

Please if any body can help me.

Thanks


Following query uses joins to update your table but if it would be faster remains to be seen.

Could you post the query plan so we can have a look at that

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'


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')

or

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' 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜