-- Actualizar campos nuevos de la tabla INCIDENCIAS de Asurnet
UPDATE A
SET A.Fusion_CLI_Id = B.Fusion_CLI_Id,
A.Fusion_OBJ_Id = B.OBJ_Id,
A.Fusion_USR_Id_FC = B.Fusion_USR_Id_FC,
A.Fusion_USR_Id_FM = B.Fusion_USR_Id_FM,
A.Fusion_INC_UsuarioCierre = B.Fusion_INC_UsuarioCierre
FROM asurnet.dbo.INCIDENCIAS A
INNER JOIN (
    SELECT A.INC_Id, B.IDTSS AS Fusion_CLI_Id, A.OBJ_Id, C.IDTSS AS Fusion_USR_Id_FC, D.IDTSS AS Fusion_USR_Id_FM, E.IDTSS AS Fusion_INC_UsuarioCierre
    FROM asurnet.dbo.INCIDENCIAS A
    LEFT JOIN tssseg0001.dbo.IDTraspasos B ON A.CLI_Id = B.IDTras AND B.TableID = 'Clientes'
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON A.USR_Id_FC = C.IDTras AND C.TableID = 'Usuarios'
    LEFT JOIN tssseg0001.dbo.IDTraspasos D ON A.USR_Id_FM = D.IDTras AND D.TableID = 'Usuarios'
    LEFT JOIN tssseg0001.dbo.IDTraspasos E ON A.INC_UsuarioCierre = E.IDTras AND E.TableID = 'Usuarios'
) B ON A.INC_Id = B.INC_Id


