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
非常感谢你 –