dbo.monitoreos_batch_2_arba

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

1
Name Data Type Length Description
@yesterday date 3

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
--exec monitoreos_batch_2
CREATE OR ALTER PROCEDURE dbo.monitoreos_batch_2_arba
@yesterday date = null

AS
BEGIN
    SET NOCOUNT ON;
 if (@yesterday is null) begin set @yesterday = GETDATE() - 1 end 
 declare @cant1 bigint
 declare @cant2 bigint
 --set @cant1 = (select COUNT(*) from juicios where CONVERT(date, created)  = @yesterday)
 --set @cant2 = (select COUNT(*) from juicios where CONVERT(date, modified) = @yesterday)

 --if (@cant1 > 0 or  @cant2 > 0) 
 --BEGIN


  declare @r_cuit varchar(20),@r_seccion_mantenimiento int
  DECLARE bn CURSOR FOR
   select distinct cuit,seccion_mantenimiento 
   from monitoreos where visible = 1 
   and isnull(seccion_mantenimiento,6) = 6  
   and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento >= @yesterday)
   and (fecha_desde is null or fecha_desde <= @yesterday)
        --and cliente = 1299789112

  -- 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
   --Inicio otro cursor para poder pegar por ID.
    declare @r_id_arba int
    DECLARE sc CURSOR
    FOR
       select distinct (id_arba) 
          from arba 
       inner join arba_tipo_impuestos as ati on ati.id_tipo_impuestos = arba.impuesto 
       inner join arba_estado_cancelacion as aec on aec.id_estado_cancelacion = cancelacion_del_juicio
       inner join arba_estado_medida_cautelar as aemc on aemc.id_estado_medida_cautelar= estado_de_medida_cautelar
       inner join arba_estado_plan_pagos as aepp on aepp.id_estado_plan_pagos = Arba.estado_de_plan_de_pagos 
       where cuit = @r_Cuit 
       AND visible = 1 
       AND ((convert(date,created) = @yesterday and created is not null) or (convert(date,modified) = @yesterday and modified is not null)) 
       AND (((((arba.fecha_de_inicio_de_juicio >= ( CONVERT(DATE,GETDATE()-1825) )) AND 
       (arba.estado_de_plan_de_pagos NOT IN ('2' ,'4' )) ) AND
       (arba.cancelacion_del_juicio NOT IN ('S' ,'T' )) ) AND 
       (arba.fecha_de_cancelacion IS NULL )) 
       OR 
       ((arba.fecha_de_inicio_de_juicio >= ( CONVERT(DATE,GETDATE()-730) )) AND 
       (((arba.estado_de_plan_de_pagos IN ('2' ,'4' ))
       OR
       (arba.cancelacion_del_juicio IN ('S' ,'T' ))) 
       OR (arba.fecha_de_cancelacion IS NOT NULL ))))
   
    -- apertura del cursor
    OPEN sc 
 
    FETCH next from sc INTO  @r_id_arba

    WHILE (@@FETCH_STATUS <> -1 )
     BEGIN
      insert into monitoreos_resultados (id_tabla,   tabla,  cuit,    seccion_mantenimiento, fecha,      novedad, tipo_novedad)
             values(@r_id_arba, 'Arba', @r_cuit, 6,                     @yesterday, 1,       'Fiscales_arba');
      update monitoreos 
          set fecha_ultimo_procesamiento = @yesterday,
           fecha_modificacion = @yesterday
         where cuit = @r_cuit 
          -- and cliente = 1299789112

         and isnull(seccion_mantenimiento,@r_seccion_mantenimiento) = @r_seccion_mantenimiento
      and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento >= @yesterday)
         and (fecha_desde is null or fecha_desde <= @yesterday)

      FETCH next from sc INTO  @r_id_arba
     END
   
     -- Cierra el cursor
     CLOSE sc
     -- Libera los recursos del cursor
     DEALLOCATE sc 
  
     FETCH next from bn INTO  @r_cuit,@r_seccion_mantenimiento

   END
   -- Cierra el cursor
   CLOSE bn
   -- Libera los recursos del cursor
   DEALLOCATE bn 
  --END
END 

GO

Used By

No items found