UPDATE A
SET A.CMD_CartaEnviada = 1
    FROM TESISSEG.dbo.AS_CAMBIOMEDIACION A
INNER JOIN (
SELECT ac.CMD_Id FROM TESISSEG.dbo.AS_CAMBIOMEDIACION ac
INNER JOIN TSSGESDOC.dbo.GesDoc gd ON gd.DocID LIKE 'MED100109N' + RIGHT('000000000000'+ CAST(ac.CMD_Id AS VARCHAR),8) + '%' AND gd.EmpID = ac.EmpID AND gd.ApaID = 'CAMBIOMEDIACION'
WHERE ac.CMD_CartaEnviada = 0 OR ac.CMD_CartaEnviada IS NULL
) B ON A.CMD_Id = B.CMD_Id

UPDATE A
SET A.CMD_DniEnviado = 1
    FROM TESISSEG.dbo.AS_CAMBIOMEDIACION A
INNER JOIN (
SELECT ac.CMD_Id FROM TESISSEG.dbo.AS_CAMBIOMEDIACION ac
INNER JOIN TSSGESDOC.dbo.GesDoc gd ON gd.DocID LIKE 'MED100045N' + RIGHT('000000000000'+ CAST(ac.CMD_Id AS VARCHAR),8) + '%' AND gd.EmpID = ac.EmpID AND gd.ApaID = 'CAMBIOMEDIACION'
WHERE ac.CMD_DniEnviado = 0 OR ac.CMD_DniEnviado IS NULL
) B ON A.CMD_Id = B.CMD_Id

UPDATE A
SET A.CMD_AutorizacionEnviada = 1
    FROM TESISSEG.dbo.AS_CAMBIOMEDIACION A
INNER JOIN (
SELECT ac.CMD_Id FROM TESISSEG.dbo.AS_CAMBIOMEDIACION ac
INNER JOIN TSSGESDOC.dbo.GesDoc gd ON gd.DocID LIKE 'MED100028N' + RIGHT('000000000000'+ CAST(ac.CMD_Id AS VARCHAR),8) + '%' AND gd.EmpID = ac.EmpID AND gd.ApaID = 'CAMBIOMEDIACION'
WHERE ac.CMD_AutorizacionEnviada = 0 OR ac.CMD_AutorizacionEnviada IS NULL
) B ON A.CMD_Id = B.CMD_Id

UPDATE A
SET A.CMD_CifEnviado = 1
    FROM TESISSEG.dbo.AS_CAMBIOMEDIACION A
INNER JOIN (
SELECT ac.CMD_Id FROM TESISSEG.dbo.AS_CAMBIOMEDIACION ac
INNER JOIN TSSGESDOC.dbo.GesDoc gd ON gd.DocID LIKE 'MED100039N' + RIGHT('000000000000'+ CAST(ac.CMD_Id AS VARCHAR),8) + '%' AND gd.EmpID = ac.EmpID AND gd.ApaID = 'CAMBIOMEDIACION'
WHERE ac.CMD_CifEnviado = 0 OR ac.CMD_CifEnviado IS NULL
) B ON A.CMD_Id = B.CMD_Id