dbo.pruebas_monitoreos_batch_10

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 pruebas_monitoreos_batch_10 '2017-07-18'
CREATE OR ALTER PROCEDURE dbo.pruebas_monitoreos_batch_10
@yesterday date = null

AS
BEGIN
    SET NOCOUNT ON;
 declare @respuesta table (cantidad int, hora datetime)

 select GETDATE() as inicio

 if (@yesterday is null) begin set @yesterday = GETDATE() - 1 end 
 declare @r_cuit varchar(20),@r_seccion_mantenimiento int
 declare @cant1 int
 declare @cant2 int 
 declare @cant3 int
 declare @cant4 int
 
 set @cant1 = 0
 set @cant2 = 0
 set @cant3 = 0
 set @cant4 = 0
 
 set @cant2 = 1
 set @cant1 = 1


 if (@cant1 > 0 or  @cant2 > 0 or @cant3 > 0 or @cant4 > 0) 
 BEGIN
  DECLARE bn CURSOR

  FOR
   select distinct cuit from monitoreos where visible = 1 and seccion_mantenimiento = 10 and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento >= @yesterday)
  
  OPEN bn 

  insert into @respuesta values (0, GETDATE())

  Fetch next from bn INTO  @r_cuit 

  WHILE (@@FETCH_STATUS <> -1 )
 
  BEGIN 
   
   set @cant3 = @cant3 + 1 
   if (@cant3 = 10000) begin break end 
   if (@cant3 % 1000 = 0)
   begin
       insert into @respuesta values (@cant3, GETDATE())
   end 
     
      --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 vigente = 1
     and ((convert(date,created) = @yesterday) or (convert(date,modified) = @yesterday)) 
   OPEN cendeuc 
    FETCH next from cendeuc INTO  @r_id_cendeu
   WHILE (@@FETCH_STATUS <> -1 )
    BEGIN 
        set @cant4 = @cant4 + 1 
        FETCH next from cendeuc INTO  @r_id_cendeu

    END
   CLOSE cendeuc
   DEALLOCATE cendeuc 
   FETCH next from bn INTO @r_cuit

  END
  CLOSE bn
  DEALLOCATE bn 
    
  insert into @respuesta values (@cant3, GETDATE())
     select cantidad, hora from @respuesta
  
 END
END 

GO

Depends On

2

Used By

No items found