UPDATE A
SET A.ciaIdTesis = B.IDTSS
    FROM asurnet.dbo.COMPETIDORES_OPT A
INNER JOIN tssseg0001.dbo.IDTraspasos B
ON A.ciaId = B.IDTras AND B.TableID = 'Companias'

UPDATE A
SET A.UserIdTesis = B.IDTSS
    FROM asurnet.dbo.CONFIGURACION_SMTP A
INNER JOIN tssseg0001.dbo.IDTraspasos B
ON A.UserId = B.IDTras AND B.TableID = 'Usuarios'

UPDATE A
SET A.usersIdTesis = B.IDTSS
    FROM asurnet.dbo.EMAIL_CONFIRMATIONS A
INNER JOIN tssseg0001.dbo.IDTraspasos B
ON A.usersId = B.IDTras AND B.TableID = 'Usuarios'

UPDATE A SET
    A.Fusion_IUC_IdObjeto = B.IDTSS
    FROM asurnet.dbo.ITEM_USUARIOCOLABORADOR A
INNER JOIN (
    SELECT B.IUC_Id,C.IDTSS
    FROM asurnet.dbo.ITEM_USUARIOCOLABORADOR B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.IUC_IdObjeto = C.IDTras AND C.TableID = 'Clientes'
    WHERE B.IUC_TipoObjeto = 1
    )
    B ON A.IUC_Id = B.IUC_Id;

UPDATE A SET
    A.Fusion_IUC_IdObjeto = B.IDTSS
    FROM asurnet.dbo.ITEM_USUARIOCOLABORADOR A
INNER JOIN (
    SELECT B.IUC_Id,C.IDTSS
    FROM asurnet.dbo.ITEM_USUARIOCOLABORADOR B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.IUC_IdObjeto = C.IDTras AND C.TableID = 'Colaboradores'
    WHERE B.IUC_TipoObjeto = 2
    )
    B ON A.IUC_Id = B.IUC_Id;

UPDATE A SET
    A.Fusion_IUC_IdObjeto = B.IUC_IdObjeto
    FROM asurnet.dbo.ITEM_USUARIOCOLABORADOR A
INNER JOIN (
    SELECT B.IUC_Id,B.IUC_IdObjeto
    FROM asurnet.dbo.ITEM_USUARIOCOLABORADOR B
    WHERE B.IUC_TipoObjeto IN (7,1000,160,44)
    )
    B ON A.IUC_Id = B.IUC_Id;

UPDATE A SET
    A.Fusion_IUC_IdObjeto = B.IDTSS
    FROM asurnet.dbo.ITEM_USUARIOCOLABORADOR A
INNER JOIN (
    SELECT B.IUC_Id,C.IDTSS
    FROM asurnet.dbo.ITEM_USUARIOCOLABORADOR B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.IUC_IdObjeto = C.IDTras AND C.TableID = 'Recibos'
    WHERE B.IUC_TipoObjeto = 10
    )
    B ON A.IUC_Id = B.IUC_Id;

UPDATE A SET
    A.Fusion_IUC_IdObjeto = B.IDTSS
    FROM asurnet.dbo.ITEM_USUARIOCOLABORADOR A
INNER JOIN (
    SELECT B.IUC_Id,C.IDTSS
    FROM asurnet.dbo.ITEM_USUARIOCOLABORADOR B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.IUC_IdObjeto = C.IDTras AND C.TableID = 'Siniestros'
    WHERE B.IUC_TipoObjeto = 13
    )
    B ON A.IUC_Id = B.IUC_Id;

UPDATE asurnet.dbo.ITEM_USUARIOCOLABORADOR
SET IUC_TipoObjeto = 44
WHERE IUC_TipoObjeto = 1044;

UPDATE A SET
    A.Fusion_OBJ_Id = B.IDTSS
    FROM asurnet.dbo.MAILS_ENVIADOS A
INNER JOIN (
    SELECT B.MENV_Id,C.IDTSS
    FROM asurnet.dbo.MAILS_ENVIADOS B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.OBJ_Id COLLATE Modern_Spanish_CI_AI = C.IDTras AND C.TableID = 'Clientes'
    WHERE B.MENV_TipoObj = 1
    )
    B ON A.MENV_Id = B.MENV_Id;

UPDATE A SET
    A.Fusion_OBJ_Id = B.IDTSS
    FROM asurnet.dbo.MAILS_ENVIADOS A
INNER JOIN (
    SELECT B.MENV_Id,C.IDTSS
    FROM asurnet.dbo.MAILS_ENVIADOS B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.OBJ_Id COLLATE Modern_Spanish_CI_AI = C.IDTras AND C.TableID = 'Colaboradores'
    WHERE B.MENV_TipoObj = 2
    )
    B ON A.MENV_Id = B.MENV_Id;

UPDATE A SET
    A.Fusion_OBJ_Id = B.OBJ_Id
    FROM asurnet.dbo.MAILS_ENVIADOS A
INNER JOIN (
    SELECT B.MENV_Id,B.OBJ_Id
    FROM asurnet.dbo.MAILS_ENVIADOS B
    WHERE B.MENV_TipoObj IN (7,1000,160)
    )
    B ON A.MENV_Id = B.MENV_Id;

UPDATE A SET
    A.Fusion_OBJ_Id = B.IDTSS
    FROM asurnet.dbo.MAILS_ENVIADOS A
INNER JOIN (
    SELECT B.MENV_Id,C.IDTSS
    FROM asurnet.dbo.MAILS_ENVIADOS B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.OBJ_Id COLLATE Modern_Spanish_CI_AI = C.IDTras AND C.TableID = 'Recibos'
    WHERE B.MENV_TipoObj = 10
    )
    B ON A.MENV_Id = B.MENV_Id;

UPDATE A SET
    A.Fusion_OBJ_Id = B.IDTSS
    FROM asurnet.dbo.MAILS_ENVIADOS A
INNER JOIN (
    SELECT B.MENV_Id,C.IDTSS
    FROM asurnet.dbo.MAILS_ENVIADOS B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.OBJ_Id COLLATE Modern_Spanish_CI_AI = C.IDTras AND C.TableID = 'Siniestros'
    WHERE B.MENV_TipoObj = 13
    )
    B ON A.MENV_Id = B.MENV_Id;

UPDATE A
SET A.NSC_IdSiniestroTesis = B.IDTSS,
    A.EmpDVID = C.IDTSS,
    A.NSC_IdUsuarioTramitadorTesis = D.IDTSS
    FROM asurnet.dbo.NOTAS_SINIESTROS_CIA A
INNER JOIN tssseg0001.dbo.IDTraspasos B
ON A.NSC_IdSiniestro = B.IDTras AND B.TableID = 'Siniestros'
    LEFT JOIN tssseg0001.dbo.IDTraspasos C
    ON A.NSC_IdOficina = C.IDTras AND C.TableID = 'Oficinas'
    INNER JOIN tssseg0001.dbo.IDTraspasos D
    ON A.NSC_IdUsuarioTramitador = D.IDTras AND D.TableID = 'Usuarios'

UPDATE A SET
    A.Fusion_SMS_ObjId = B.IDTSS
    FROM asurnet.dbo.SMS_ENVIADOS A
INNER JOIN (
    SELECT B.SMS_Id,C.IDTSS
    FROM asurnet.dbo.SMS_ENVIADOS B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.SMS_ObjId = C.IDTras AND C.TableID = 'Clientes'
    WHERE B.SMS_TipoObjeto = 1
    )
    B ON A.SMS_Id = B.SMS_Id;

UPDATE A SET
    A.Fusion_SMS_ObjId = B.IDTSS
    FROM asurnet.dbo.SMS_ENVIADOS A
INNER JOIN (
    SELECT B.SMS_Id,C.IDTSS
    FROM asurnet.dbo.SMS_ENVIADOS B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.SMS_ObjId = C.IDTras AND C.TableID = 'Colaboradores'
    WHERE B.SMS_TipoObjeto = 2
    )
    B ON A.SMS_Id = B.SMS_Id;

UPDATE A SET
    A.Fusion_SMS_ObjId = B.SMS_ObjId
    FROM asurnet.dbo.SMS_ENVIADOS A
INNER JOIN (
    SELECT B.SMS_Id,B.SMS_ObjId
    FROM asurnet.dbo.SMS_ENVIADOS B
    WHERE B.SMS_TipoObjeto IN (7,1000,160)
    )
    B ON A.SMS_Id = B.SMS_Id;

UPDATE A SET
    A.Fusion_SMS_ObjId = B.IDTSS
    FROM asurnet.dbo.SMS_ENVIADOS A
INNER JOIN (
    SELECT B.SMS_Id,C.IDTSS
    FROM asurnet.dbo.SMS_ENVIADOS B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.SMS_ObjId = C.IDTras AND C.TableID = 'Recibos'
    WHERE B.SMS_TipoObjeto = 10
    )
    B ON A.SMS_Id = B.SMS_Id;

UPDATE A SET
    A.Fusion_SMS_ObjId = B.IDTSS
    FROM asurnet.dbo.SMS_ENVIADOS A
INNER JOIN (
    SELECT B.SMS_Id,C.IDTSS
    FROM asurnet.dbo.SMS_ENVIADOS B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.SMS_ObjId = C.IDTras AND C.TableID = 'Siniestros'
    WHERE B.SMS_TipoObjeto = 13
    )
    B ON A.SMS_Id = B.SMS_Id;

UPDATE A SET
    A.Fusion_OBJ_Id = B.IDTSS
    FROM asurnet.dbo.TRAMITADORES A
INNER JOIN (
    SELECT B.TRA_Id,C.IDTSS
    FROM asurnet.dbo.TRAMITADORES B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.OBJ_Id = C.IDTras AND C.TableID = 'Clientes'
    WHERE B.TRA_TipoObj = 1
    )
    B ON A.TRA_Id = B.TRA_Id;

UPDATE A SET
    A.Fusion_OBJ_Id = B.IDTSS
    FROM asurnet.dbo.TRAMITADORES A
INNER JOIN (
    SELECT B.TRA_Id,C.IDTSS
    FROM asurnet.dbo.TRAMITADORES B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.OBJ_Id = C.IDTras AND C.TableID = 'Colaboradores'
    WHERE B.TRA_TipoObj = 2
    )
    B ON A.TRA_Id = B.TRA_Id;

UPDATE A SET
    A.Fusion_OBJ_Id = B.OBJ_Id
    FROM asurnet.dbo.TRAMITADORES A
INNER JOIN (
    SELECT B.TRA_Id,B.OBJ_Id
    FROM asurnet.dbo.TRAMITADORES B
    WHERE B.TRA_TipoObj IN (7,1000,160,44)
    )
    B ON A.TRA_Id = B.TRA_Id;

UPDATE A SET
    A.Fusion_OBJ_Id = B.IDTSS
    FROM asurnet.dbo.TRAMITADORES A
INNER JOIN (
    SELECT B.TRA_Id,C.IDTSS
    FROM asurnet.dbo.TRAMITADORES B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.OBJ_Id = C.IDTras AND C.TableID = 'Recibos'
    WHERE B.TRA_TipoObj = 10
    )
    B ON A.TRA_Id = B.TRA_Id;

UPDATE A SET
    A.Fusion_OBJ_Id = B.IDTSS
    FROM asurnet.dbo.TRAMITADORES A
INNER JOIN (
    SELECT B.TRA_Id,C.IDTSS
    FROM asurnet.dbo.TRAMITADORES B
    LEFT JOIN tssseg0001.dbo.IDTraspasos C ON B.OBJ_Id = C.IDTras AND C.TableID = 'Siniestros'
    WHERE B.TRA_TipoObj = 13
    )
    B ON A.TRA_Id = B.TRA_Id;

UPDATE A
SET A.EmpDVID = B.IDTSS
    FROM asurnet.dbo.WSC_OFICINAS A
INNER JOIN tssseg0001.dbo.IDTraspasos B
ON A.OFI_Id = B.IDTras AND B.TableID = 'Oficinas'
