update acr
set acr.PostingDate = (case when acrO.PostingDate is not null then acrO.PostingDate
							when visit.VisitDate is not null then visit.VisitDate
							else eb.EventDate end)
from AKUZ.T_AMBULANCE_CARD_RECORD acr 
join AKUZ.T_ACCOMPANYING_DISEASES ad on acr.MedicalRecordID = ad.MedicalRecordID
join AKUZ.T_AMBULANCE_CARD_RECORD acrO on acrO.MedicalRecordID = ad.OutcomeOfInspection
join AKUZ.T_EVENT_BASE eb on eb.EventID = acr.AmbulanceEvent
outer apply(
	select top 1 v.VisitDate from AKUZ.T_VISIT v where v.OutcomeRecord = ad.OutcomeOfInspection
) visit
where acr.PostingDate is null