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
 General SQL Server Forums
 New to SQL Server Programming
 single statment

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2008-03-13 : 08:53:48
iam having two statement for updating one table.
just i need to club into one statment.can any one tell how this can be achieved.

first statement:
===================
--Updating Customer code
update stg
set stg.customer_code=dtl.cgd_customer_code
from Subsidiary_Ageing_tb stg(nolock) inner join fin_ods..cust_group_dtl dtl(nolock)
on dtl.cgd_cust_group_code=stg.customer_grp

second statment:
===================
--updating customer name
update stg
set stg.customer_name=dtl.clo_cust_name
from Subsidiary_Ageing_tb stg(nolock) inner join fin_ods..cust_lo_info dtl(nolock)
on dtl.clo_cust_code=stg.customer_code

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-13 : 08:58:03
[code]UPDATE stg
SET stg.customer_code = COALESCE(dtl.cgd_customer_code, stg.customer_code),
stg.customer_name = COALESCE(dt2.clo_cust_name, stg.customer_name)
FROM Subsidiary_Ageing_tb AS stg WITH (NOLOCK)
LEFT JOIN fin_ods..cust_group_dtl AS dtl WITH (NOLOCK) ON dtl.cgd_cust_group_code = stg.customer_grp
LEFT JOIN fin_ods..cust_lo_info AS dt2 WITH (NOLOCK) ON dt2.clo_cust_code = stg.customer_code[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -