0
我有兩個表,並希望插入或更新從tableA到TableB chages。如何在merge語句的`when`子句中使用條件?
PatientId
和ComposeId
兩個表
table A
PatientId
ComposeId
Name
Family
table B
PatientId
ComposeId
Name
Family
我想要實現這樣的事情,或者可能使用嵌套合併的複合鍵。怎麼做?
Merge TbleB as Target
using (select PatientId,Compseid,Name,Family from TableA) as source
on (source.PatientId=target.PatientId and source.ComposeId=target.Composeid and source.Name=Target.Name
and Source.Family=target.Family)
when not matched and source.patientId=target.PatientId and Source.CompositionId=Target.CompistionId
then update
set Name=Source.Name,
set Family=Source.Family
when not matched and (source.patientId<>target.PatientId and Source.CompositionId<>Target.CompistionId) then
Insert
非常感謝你 –