仅在两个表中的FirstName LastName和DateofBirth列都匹配的情况下,我才打算用Patientdemographics2中名为custom的列来更新Patientdemograpics中的一列。
Update PatientDemographics
Set PatientDemographics.custom = PatientDemographics2.custom
FROM PatientDemographics INNER JOIN
PatientDemographics2 ON
Patientdemographics.FirstName = Patientdemographics2.FirstName and
Patientdemographics.LastName = Patientdemographics2.LastName and
Patientdemographics.DateofBirth = Patientdemographics.DateofBirth
where Patientdemographics.FirstName = Patientdemographics2.FirstName and
Patientdemographics.LastName = Patientdemographics2.LastName and
Patientdemographics.DateofBirth = Patientdemographics.DateofBirth
答案 0 :(得分:2)
您在ON
子句的最后一个条件中输入错误:
Patientdemographics.DateofBirth = Patientdemographics.DateofBirth
应该是:
Patientdemographics.DateofBirth = Patientdemographics2.DateofBirth
,还有一个无用 WHERE
子句,因为它的所有条件都已在ON
子句中应用。
还使用别名使代码更简单,更易读:
Update p
Set p.custom = p2.custom
FROM PatientDemographics AS p INNER JOIN PatientDemographics2 AS p2
ON
p.FirstName = p2.FirstName and
p.LastName = p2.LastName and
p.DateofBirth = p2.DateofBirth