ALTER TABLE akuz.t_dispanserisation_init
ADD COLUMN CurrentMkb VARCHAR(8);

ALTER TABLE akuz.t_dispanserisation_init
ADD COLUMN CurrentDiagnosis VARCHAR(4096);

WITH cte AS (
    SELECT mov.DispanserisationInit, mov.Mkb, mov.Diagnosis
    FROM akuz.T_DISPANSERISATION_MOVENMENT mov
    WHERE NOT EXISTS (
        SELECT 1
        FROM akuz.T_DISPANSERISATION_MOVENMENT mov2
        WHERE mov2.DateEditing > mov.DateEditing
          AND mov.DispanserisationInit = mov2.DispanserisationInit
    )
)
UPDATE akuz.T_DISPANSERISATION_INIT di
SET 
    CurrentDiagnosis = COALESCE(cte.Diagnosis, di.Diagnosis),
    CurrentMkb       = COALESCE(cte.Mkb, di.Mkb)
FROM cte
WHERE di.MedicalRecordId = cte.DispanserisationInit;

UPDATE AKUZ.T_DISPANSERISATION_INIT
SET
    CurrentDiagnosis = Diagnosis
WHERE CurrentDiagnosis IS NULL;

UPDATE AKUZ.T_DISPANSERISATION_INIT
SET
    CurrentMkb = Mkb
WHERE CurrentMkb IS NULL;