Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 simplify two updates into one

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-09-30 : 10:16:22
Is it possible to simplify the following two updates by placing them into one update ?
Thanks

update
y
set
y.Field1 = ipc.Yld
from
tblY as y inner join CCcy as cc
on (y.Ccy = cc.Ccy and y.ICode = cc.ICode)
inner join @IPC as ipc
on (cc.Ccy = ipc.Ccy and cc.Name = ipc.Country)
where
ipc.LngDur = '0-x'


update
y
set
y.Field2 = ipc.Yld
from
tblY as y inner join CCcy as cc
on (y.Ccy = cc.Ccy and y.ICode = cc.ICode)
inner join @IPC as ipc
on (cc.Ccy = ipc.Ccy and cc.Name = ipc.Country)
where
ipc.LngDur = '5-9'

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-30 : 10:59:10
[code]
update
y
set
y.Field1 = case when ipc.LngDur = '0-x' then ipc.Yld else y.Field1 end,
y.Field2 = case when ipc.LngDur = '5-9' then ipc.Yld else y.Field2 end
from
tblY as y inner join CCcy as cc
on (y.Ccy = cc.Ccy and y.ICode = cc.ICode)
inner join @IPC as ipc
on (cc.Ccy = ipc.Ccy and cc.Name = ipc.Country)
where
ipc.LngDur in ( '0-x','5-9')
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-09-30 : 10:59:49
[code]
update y
set y.Field1 = case when ipc.LngDur = '0-x' then ipc.Yld else y.Field1 end,
y.Field2 = case when ipc.LngDur = '5-9' then ipc.Yld else y.Field2 end
from tblY as y
inner join CCcy as cc on (y.Ccy = cc.Ccy and y.ICode = cc.ICode)
inner join @IPC as ipc on (cc.Ccy = ipc.Ccy and cc.Name = ipc.Country)
where ipc.LngDur in ( '0-x' , '5-9')
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-09-30 : 11:00:35



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -