dbo.sp_posiciones_fijas_cuit_a_afip

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
/*
select  idreg, cuit_asignado
  from posiciones_fijas 
 where procesado_cuit = 1 
   and procesado_afip = 0
*/

/*

exec sp_posiciones_fijas_cuit_a_afip

*/

CREATE OR ALTER PROCEDURE dbo.sp_posiciones_fijas_cuit_a_afip 
AS
BEGIN
    SET NOCOUNT ON;
 DECLARE @idreg INT, @cuit varchar(20),@yaprocesado int, @aprocesar int 

 DECLARE C_pos CURSOR FOR
  select top 3000 idreg, cuit_asignado
    from posiciones_fijas 
   where procesado_cuit = 1 
     and procesado_afip = 0

 OPEN C_pos
 FETCH NEXT FROM C_pos INTO @idreg,@cuit
 WHILE @@fetch_status = 0
 BEGIN
  
  set @aprocesar = (select count(*) from consultar_afip where cuit = @cuit and proceso = 'WORLDSYS14082018')
  if (@aprocesar = 0)
  begin
   set @yaprocesado = (SELECT count(*) from servicios_externos_cuits_consultados where identificacion = @cuit and servicio = 'AFIP' and fecha >= dateadd(day,-90,getdate()))
   if (@yaprocesado = 0) 
   begin
    insert into consultar_afip (proceso, cuit, procesado,fecha) 
    values ('WORLDSYS14082018', @cuit, 0,'2018-08-14')
   end
  end  
  update posiciones_fijas set procesado_afip = 1 where idreg = @idreg
  FETCH NEXT FROM C_pos INTO @idreg, @cuit
 END  
 CLOSE C_pos
 DEALLOCATE C_pos
END
GO