UPDATE
        akuz.T_MEDICAL_EPISODE AS episode
SET
        DateOut = me.ExaminationDate
FROM
        akuz.T_MEDICAL_EXAMINATION_DATA med
JOIN
        akuz.T_MEDICAL_EXAMINATION me
ON
        me.MedicalRecordID = med.LastMedicalExamination
WHERE
        med.MedicalEpisodeID = episode.MedicalEpisodeID
AND     episode.DateOut != me.ExaminationDate;