dbo.--monitoreos_batch

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

CREATE OR ALTER PROCEDURE dbo.[--monitoreos_batch]

AS
BEGIN
    SET NOCOUNT ON;

 declare @r_cuit varchar(20),@r_seccion_mantenimiento int
DECLARE bn CURSOR

FOR
 select distinct cuit,seccion_mantenimiento from monitoreos where visible = 1 and (seccion_mantenimiento = 9 or seccion_mantenimiento = 10)
-- apertura del cursor

OPEN bn 

 
 
-- Lectura de la primera fila del cursor
Fetch next from bn INTO  @r_cuit, @r_seccion_mantenimiento

 


WHILE (@@FETCH_STATUS <> -1 )

 
 
BEGIN
 declare @yesterday date=  getdate() - 1
 /*if(@r_seccion_mantenimiento = 2)
  begin
  declare @formales int
  select @formales = count(*) from domicilios_todos where cuit = @r_cuit and 
  (convert(date,created) >= @yesterday and created is not null or modified >= @yesterday and modified is not null) and visible = 1
  if(@formales > 0)
  begin
 
  insert into monitoreos_resultados (cuit,seccion_mantenimiento,fecha,novedad,tipo_novedad)values(@r_cuit,2,getdate(),1,'Formales');
  update monitoreos set fecha_ultimo_procesamiento=getdate(),fecha_modificacion=getdate() where cuit= @r_cuit and seccion_mantenimiento =@r_seccion_mantenimiento
  end
  end
  if(@r_seccion_mantenimiento = 5)
  begin
  declare @comerciales int
  select @comerciales = count(*) from contador_consultas where cuit_consultado = @r_cuit and 
  (convert(date,created) >= @yesterday and created is not null or modified >= @yesterday and modified is not null) and visible = 1
  if(@comerciales > 0)
  begin
  insert into monitoreos_resultados (cuit,seccion_mantenimiento,fecha,novedad,tipo_novedad)values(@r_cuit,5,getdate(),1,'Comerciales');
  update monitoreos set fecha_ultimo_procesamiento=getdate(),fecha_modificacion=getdate() where cuit= @r_cuit and seccion_mantenimiento =@r_seccion_mantenimiento
  end
  end
  if(@r_seccion_mantenimiento = 6)
  begin
  declare @arba int,@inscripciones int
  select @arba = count(*) from arba where cuit = @r_cuit and 
  (convert(date,created) >= @yesterday and created is not null or modified >= @yesterday and modified is not null) and visible = 1
  select @inscripciones = count(*) from inscripciones where cuit = @r_cuit and 
  (convert(date,created) >= @yesterday and created is not null or modified >= @yesterday and modified is not null) and inscripciones.activo= 1
 
  if(@arba > 0 OR @inscripciones > 0)
  begin
  insert into monitoreos_resultados (cuit,seccion_mantenimiento,fecha,novedad,tipo_novedad)values(@r_cuit,6,getdate(),1,'Fiscales');
  update monitoreos set fecha_ultimo_procesamiento=getdate(),fecha_modificacion=getdate() where cuit= @r_cuit and seccion_mantenimiento =@r_seccion_mantenimiento
 
  end
  end
  if(@r_seccion_mantenimiento = 7)
  begin
  declare @contables int
  select @contables = count(*) from balances_contables where cuit = @r_cuit and 
  (convert(date,created) >= @yesterday and created is not null or modified >= @yesterday and modified is not null) and visible = 1
  if(@contables > 0)
  begin
  insert into monitoreos_resultados (cuit,seccion_mantenimiento,fecha,novedad,tipo_novedad)values(@r_cuit,7,getdate(),1,'Contables');
  update monitoreos set fecha_ultimo_procesamiento=getdate(),fecha_modificacion=getdate() where cuit= @r_cuit and seccion_mantenimiento =@r_seccion_mantenimiento
  end
  end
  if(@r_seccion_mantenimiento = 8)
  begin
  declare @datos_sociedades int, @constituciones int
  select @datos_sociedades = count(*) from datos_sociedades where cuit = @r_cuit and 
  (convert(date,created) >= @yesterday and created is not null or modified >= @yesterday and modified is not null)
  select @constituciones = count(*) from CONSTITUCIONES where cuit_soc = @r_cuit and 
  (convert(date,created) >= @yesterday and created is not null or modified >= @yesterday and modified is not null)
 
  if(@datos_sociedades > 0 OR @constituciones > 0)
  begin
  insert into monitoreos_resultados (cuit,seccion_mantenimiento,fecha,novedad,tipo_novedad)values(@r_cuit,8,getdate(),1,'Relaciones');
  update monitoreos set fecha_ultimo_procesamiento=getdate(),fecha_modificacion=getdate() where cuit= @r_cuit and seccion_mantenimiento =@r_seccion_mantenimiento
  end
  end*/

 if(@r_seccion_mantenimiento = 9)
 begin
 
  --Inicio otro cursor para poder pegar por ID.
   declare @r_id_juicio int
   DECLARE juiciosc CURSOR
   FOR
    select distinct(id_juicio) 
      from juicios 
     where (cuit_actor = @r_cuit OR cuit_demandado = @r_cuit) 
       and ((convert(date,created) = @yesterday and created is not null) or (modified = @yesterday and modified is not null)) 
        and visible = 1
   
   -- apertura del cursor
   OPEN juiciosc 
 
   FETCH next from juiciosc INTO  @r_id_juicio

   WHILE (@@FETCH_STATUS <> -1 )
    BEGIN
     insert into monitoreos_resultados (id_juicio,    cuit,    seccion_mantenimiento, fecha,     novedad, tipo_novedad)
                                 values(@r_id_juicio, @r_cuit, 9,                     getdate(), 1,       'Legales');
     update monitoreos 
            set fecha_ultimo_procesamiento = getdate(),
                fecha_modificacion = getdate() 
            where cuit = @r_cuit and seccion_mantenimiento = @r_seccion_mantenimiento
     FETCH next from juiciosc INTO  @r_id_juicio
    END
   

   -- Cierra el cursor
   CLOSE juiciosc

   -- Libera los recursos del cursor

   DEALLOCATE juiciosc 
  
  end
  
 



 if(@r_seccion_mantenimiento = 10 )
 begin
   
  --Inicio otro cursor para poder pegar por ID.
  declare @r_id_cendeu int
  DECLARE cendeuc CURSOR
  FOR
   select distinct(id_cendeu)
     from cendeu 
     where iden = @r_cuit 
          and ((convert(date,created) = @yesterday and created is not null) or (modified = @yesterday and modified is not null)) 
       and vigente = 1
  -- apertura del cursor

  OPEN cendeuc 
 
  FETCH next from cendeuc INTO  @r_id_cendeu

  WHILE (@@FETCH_STATUS <> -1 )
   BEGIN
    insert into monitoreos_resultados 
           (id_cendeu,    cuit,    seccion_mantenimiento, fecha,     novedad, tipo_novedad)
    values (@r_id_cendeu, @r_cuit, 10,                    getdate(), 1,       'Bancos');
    update monitoreos 
       set fecha_ultimo_procesamiento = getdate(),
           fecha_modificacion = getdate() 
        where cuit= @r_cuit and seccion_mantenimiento = @r_seccion_mantenimiento
    FETCH next from cendeuc INTO  @r_id_cendeu
   END

   

  -- Cierra el cursor
  CLOSE cendeuc

  -- Libera los recursos del cursor

  DEALLOCATE cendeuc 

 end
 
 
 /*if(@r_seccion_mantenimiento = 11 )
  begin
  declare @comex int
  select @comex = count(*) from comex_pais where cuit = @r_cuit and 
  (convert(date,created) >= @yesterday and created is not null or modified >= @yesterday and modified is not null) and activo= 1
  if(@comex > 0 )
  begin
  insert into monitoreos_resultados (cuit,seccion_mantenimiento,fecha,novedad,tipo_novedad)values(@r_cuit,11,getdate(),1,'Comex');
  update monitoreos set fecha_ultimo_procesamiento=getdate(),fecha_modificacion=getdate() where cuit= @r_cuit and seccion_mantenimiento =@r_seccion_mantenimiento
  end
  end*/



  FETCH next from bn INTO  @r_cuit,@r_seccion_mantenimiento

END

 

-- Cierra el cursor

CLOSE bn

-- Libera los recursos del cursor

DEALLOCATE bn 

-- insert into
END
GO

Used By

No items found