-- Actualizar el valor del colaborador y usuario de Te-sis obteniendo el ID del traspaso de Te-sis
UPDATE A
SET A.ColID = B.ColID,
A.UseID = B.UseID
FROM asurnet.dbo.MAILS_ENVIADOS A
INNER JOIN (
	SELECT A.MENV_Id, B.IDTSS AS ColID, C.IDTSS AS UseID
	FROM asurnet.dbo.MAILS_ENVIADOS A
	LEFT JOIN tssseg0001.dbo.IDTraspasos B
	ON A.COL_Id = B.IDTras COLLATE Modern_Spanish_CI_AI AND B.TableID = 'Colaboradores'
    INNER JOIN tssseg0001.dbo.IDTraspasos C
    ON A.USR_Id = C.IDTras AND C.TableID = 'Usuarios'
) B ON A.MENV_Id = B.MENV_Id
