-- Actualizar Objetos existentes en Asurnet
UPDATE A
SET A.Fusion_CON_ObjId = B.IDTSS
FROM asurnet.dbo.CONEXION_OBJETOS A
         INNER JOIN (
    SELECT *
    FROM asurnet.dbo.CONEXION_OBJETOS A
             LEFT JOIN tssseg0001.dbo.IDTraspasos B ON A.CON_ObjId = B.IDTras AND B.TableID = 'Clientes'
) B ON A.CON_Id = B.CON_Id
WHERE A.CON_TipoObj = 1

UPDATE A
SET A.Fusion_CON_ObjId = B.IDTSS
FROM asurnet.dbo.CONEXION_OBJETOS A
         INNER JOIN (
    SELECT *
    FROM asurnet.dbo.CONEXION_OBJETOS A
             LEFT JOIN tssseg0001.dbo.IDTraspasos B ON A.CON_ObjId = B.IDTras AND B.TableID = 'Colaboradores'
) B ON A.CON_Id = B.CON_Id
WHERE A.CON_TipoObj = 2

UPDATE A
SET A.Fusion_CON_ObjId = B.IDTSS
FROM asurnet.dbo.CONEXION_OBJETOS A
         INNER JOIN (
    SELECT *
    FROM asurnet.dbo.CONEXION_OBJETOS A
             LEFT JOIN tssseg0001.dbo.IDTraspasos B ON A.CON_ObjId = B.IDTras AND B.TableID = 'Companias'
) B ON A.CON_Id = B.CON_Id
WHERE A.CON_TipoObj = 3

--Polizas no se convierten
UPDATE A
SET A.Fusion_CON_ObjId = A.CON_ObjId
FROM asurnet.dbo.CONEXION_OBJETOS A
WHERE A.CON_TipoObj = 7

UPDATE A
SET A.Fusion_CON_ObjId = B.IDTSS
FROM asurnet.dbo.CONEXION_OBJETOS A
         INNER JOIN (
    SELECT *
    FROM asurnet.dbo.CONEXION_OBJETOS A
             LEFT JOIN tssseg0001.dbo.IDTraspasos B ON A.CON_ObjId = B.IDTras AND B.TableID = 'Recibos'
) B ON A.CON_Id = B.CON_Id
WHERE A.CON_TipoObj = 10

UPDATE A
SET A.Fusion_CON_ObjId = A.CON_ObjId
FROM asurnet.dbo.CONEXION_OBJETOS A 
WHERE A.CON_TipoObj = 160

UPDATE A
SET A.Fusion_CON_ObjId = B.IDTSS
FROM asurnet.dbo.CONEXION_OBJETOS A
         INNER JOIN (
    SELECT *
    FROM asurnet.dbo.CONEXION_OBJETOS A
             LEFT JOIN tssseg0001.dbo.IDTraspasos B ON A.CON_ObjId = B.IDTras AND B.TableID = 'Cotizaciones'
) B ON A.CON_Id = B.CON_Id
WHERE A.CON_TipoObj = 161

UPDATE A
SET A.Fusion_CON_ObjId = A.CON_ObjId
FROM asurnet.dbo.CONEXION_OBJETOS A 
WHERE A.CON_TipoObj = 1000

UPDATE A
SET A.Fusion_CON_ObjId = B.IDTSS
FROM asurnet.dbo.CONEXION_OBJETOS A
         INNER JOIN (
    SELECT *
    FROM asurnet.dbo.CONEXION_OBJETOS A
             LEFT JOIN tssseg0001.dbo.IDTraspasos B ON A.CON_ObjId = B.IDTras AND B.TableID = 'Siniestros'
) B ON A.CON_Id = B.CON_Id
WHERE A.CON_TipoObj = 13
