SELECT PatientKey = P.PatientKey , AgeKey = PM.AgeKey , GenderKey = P.GenderKey , GenderCode = P.GenderCode , GPPracticeKey = P.GPPracticeKey , GPCodeKey = P.GPCodeKey -- , PCTKey = P.PCTKey --, PCTCode = P.PCTCode --Added on 11/04/2007 , GPPracticeCode = P.GPPracticeCode -- , LocationKey = P.LocationKey , DeprivationIMDKey = PM.DeprivationIMDKey , DeprivationNationalKey = PM.DeprivationNationalKey FROM dbo.LoadConsultationsOP SCOP INNER JOIN dbo.Patient P ON SCOP.PatientId = P.PatientId INNER JOIN dbo.PatientMonths PM ON P.PatientKey = PM.PatientKey AND SCOP.DatePeriodKey = PM.DatePeriodKey
UPDATE SCOP SET PatientKey = P.PatientKey , AgeKey = PM.AgeKey , GenderKey = P.GenderKey , GenderCode = P.GenderCode , GPPracticeKey = P.GPPracticeKey , GPCodeKey = P.GPCodeKey -- , PCTKey = P.PCTKey --, PCTCode = P.PCTCode --Added on 11/04/2007 , GPPracticeCode = P.GPPracticeCode -- , LocationKey = P.LocationKey , DeprivationIMDKey = PM.DeprivationIMDKey , DeprivationNationalKey = PM.DeprivationNationalKey FROM dbo.LoadConsultationsOP SCOP INNER JOIN dbo.Patient P ON SCOP.PatientId = P.PatientId INNER JOIN dbo.PatientMonths PM ON P.PatientKey = PM.PatientKey AND SCOP.DatePeriodKey = PM.DatePeriodKey