UPDATE mri
SET F042Trekmp = (
    SELECT TOP 1 tr.F042TrekmpID
    FROM ies.T_F042_TREKMP tr
    JOIN ies.T_F004_EXPERT ex ON tr.N_EXPERT = ex.N_EXPERT
    WHERE ex.N_EXPERT = mri.Expert
    ORDER BY tr.DATEBEG DESC
)
FROM ies.T_MEDICAL_REQUEST_ITEM mri
WHERE mri.F042Trekmp IS NULL;
