dbo.monitoreos_cheques_ant

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
--Store para el monitoreo de cheques en proceso batch, para saber si tiene alguna actualizacion
CREATE OR ALTER PROCEDURE dbo.monitoreos_cheques_ant

AS
BEGIN
    SET NOCOUNT ON;

 declare @r_cuit varchar(20),@r_nro_cheque varchar(20)
DECLARE bn CURSOR

FOR
 select distinct cuit, nro_cheque from monitoreos where visible = 1
-- apertura del cursor

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

WHILE (@@FETCH_STATUS <> -1 )
 
BEGIN

        declare @yesterday date = getdate() - 1
  declare @chequesBCRA int

  set @r_nro_cheque = RTRIM(ltrim(@r_nro_cheque))

  if (@r_nro_cheque = '') 
  begin 
      set @r_nro_cheque = null 
  end 

  select @chequesBCRA = count(*) 
  from ChequesBCRA where cuit_firmante = @r_cuit 
   and ((convert(date,created) = @yesterday and created is not null) or (modified = @yesterday and modified is not null))
   and (nro_cheque = @r_nro_cheque or @r_nro_cheque is null)
  
  if (@chequesBCRA > 0 ) 
  begin
      
   insert into monitoreos_resultados 
              (nro_cheque,    cuit,    seccion_mantenimiento, fecha,     novedad, tipo_novedad)
        values(@r_nro_cheque, @r_cuit, 99,                    getdate(), 1,       'Cheques');
   update monitoreos 
      set fecha_ultimo_procesamiento = getdate(),
          fecha_modificacion=getdate()
       where cuit = @r_cuit and (nro_cheque = @r_nro_cheque or @r_nro_cheque is null)

  end


  FETCH next from bn INTO @r_cuit, @r_nro_cheque

END

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

END

GO

Used By

No items found