Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
2| Name | Data Type | Length | Description |
|---|---|---|---|
| @pIDTaken | int | 4 | |
| @error | int | 4 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
EXEC AFIP_GET_BATCH_NOCTURNO_ID 100
EXEC AFIP_GET_BATCH_NOCTURNO
*/
CREATE OR ALTER PROCEDURE dbo.AFIP_GET_BATCH_NOCTURNO_1
@pIDTaken int,
@error int
AS
BEGIN
SET NOCOUNT ON;
declare @top int
declare @top2 int
declare @iConsulta int
declare @var1 varchar(50) = 'ESTRELLA' -- 'FNAC2021' --'PAEIMPERIUM'--'SUBCAMX'--'FNAC202006A'
declare @var2 varchar(50) = 'FNAC2021'-- 'SOBLIGADOS' -- 'FNAC202105B' -- 'SOBLIGADOS'
declare @varFinal varchar(50)
/*
PARA CONTROL
declare @procesadosHoy int
declare @limiteDiario int = 120000
declare @limiteHoy int
declare @RestanHoy int
declare @TotalAProcesar int
declare @Avance money
declare @ProcesadosTotales int
declare @error int
--update consultar_afip set procesado=0,ierror=0,id_taken=0 where procesado = 1 and ierror=1
select @procesadoshoy = count(*) from consultar_afip where procesado = 1 and convert(date,fecha_proceso) = convert(date,getdate())
--select @RestanHoy= count(*) from consultar_afip where isnull(procesado,0) = 0 -- and proceso in ('SOBLIGADOS','FNAC2021')
set @RestanHoy = @limiteDiario-@procesadosHoy
select @TotalAProcesar= count(*) from consultar_afip where procesado = 0 -- proceso in ('FNAC2021')
select @ProcesadosTotales= count(*) from consultar_afip where isnull(procesado,0) = 1 and convert(date,fecha_proceso) = convert(date,getdate()) -- proceso in ('FNAC2021') and
set @limiteHoy = @limiteDiario-@procesadosHoy
set @Avance = (@ProcesadosTotales*100)/@TotalAProcesar
select @error = count(*) from consultar_afip where isnull(procesado,0) = 1 and ierror=1 --proceso in ('FNAC2021') and
select @RestanHoy as RestanHoy,@limiteDiario as limiteDiario,@procesadosHoy as ProcesadosHoy,@limiteHoy as limiteHoy,@TotalAProcesar as TotalAProcesar,@Avance as Avance,@error as Errores
select count(*) from consultar_afip where proceso = 'AA_FALLECIDOS_3' AND procesado = 0
--and substring(cuit,1,2)!='24'
select count(*) from consultar_afip where proceso = 'AA_FALLECIDOS_3' AND procesado = 1 and ierror=1
--select * from consultar_afip where proceso = 'BALANCES' AND procesado = 0 and ierror=1
-- select * from consultar_afip where proceso = 'AA_FALLECIDOS_3' AND procesado = 0 and substring(cuit,1,2)='24'
-- update consultar_afip set id_taken=0,prioridad=5 where proceso = 'AA_FALLECIDOS_3' AND procesado = 0 and substring(cuit,1,2)='24'
*/
-- select * from padrones where iscreated > getdate()-1 or ismodified > getdate()-1
-- select * from consultar_afip where procesado = 0 and ierror=0 and id_taken=80
-- select * from consultar_afip where proceso = 'AA_FALLECIDOS_3' AND procesado = 0
-- select * from consultar_afip where procesado = 0 and id_taken=100
--select * from consultar_afip where procesado = 1 and ierror=1
--update consultar_afip set procesado=0,ierror=0,id_taken=0 where procesado = 1 and ierror=1
--update consultar_afip set prioridad = 1,procesado=0,ierror=0,id_taken=0 where procesado = 0 and id_taken=300
select @top = count(*) from consultar_afip where procesado = 1 and convert(date,fecha_proceso) = convert(date,getdate())
select @iConsulta =count(*) from consultar_afip where isnull(procesado,0) = 0 and proceso IN ( @var1)
set @top2=120000-@top
--select @top as ATOP,@top2 as TOP2
-- select distinct id_taken from consultar_afip where procesado=0
--select * from consultar_afip where id_taken=100 and procesado=0
--update consultar_afip set id_taken=0 where id_taken=80 and procesado=0
if (@top2 > 250)
BEGIN
SET @TOP2 = 250
END
if (@top2 < 0)
BEGIN
SET @TOP2 = 0
END
if (@pIDTaken != 80)
begin
update top (@top2) consultar_afip set id_taken=@pIDTaken
where isnull(procesado,0) = 0 and (isnull(id_taken,0) in (0,@pIDTaken))
and idreg in (select TOP (@top2) idreg from consultar_afip where isnull(procesado,0) = 0
and (isnull(id_taken,0) in (0,@pIDTaken)) and substring(cuit,1,2) not in ('20','23','24','27')
ORDER BY prioridad,CUIT desc
)
select TOP (@top2) proceso,cuit,fecha,procesado,idreg,ierror,isnull(prioridad,10) as prioridad
from consultar_afip where isnull(procesado,0) = 0
and id_taken = @pIDTaken and substring(cuit,1,2) not in ('20','23','24','27')
ORDER BY prioridad,fecha asc,CUIT desc
end
/*
in--sert into consultar_afip (proceso,cuit,fecha,procesado,fecha_proceso,ierror)
select top 50000 'FNAC2021' AS proceso,c01_cuit as cuit, '2021-05-05' as fecha,0 as procesado,null as fecha_proceso,0 as ierror from DATOS_PERSONAS where c02_fecha_nac is null and substring(c01_cuit,1,2) in ('20','23','24','27')
AND c01_cuit NOT IN ( SELECT DISTINCT CUIT FROM CONSULTAR_AFIP WHERE PROCESO in ('FNAC202006A','FNAC2021'))
order by cuit desc
select count(*) from DATOS_PERSONAS where c02_fecha_nac is null and substring(c01_cuit,1,2) in ('20','23','24','27')
AND c01_cuit NOT IN ( SELECT DISTINCT CUIT FROM CONSULTAR_AFIP WHERE PROCESO in ('FNAC202006A','FNAC2021'))
-- update consultar_afip set procesado = 0,ierror=0 where isnull(procesado,0) = 1 and ierror=1 --proceso in ('SOBLIGADOS','FNAC2021') and
*/
END
GO
GO
/*
EXEC AFIP_GET_BATCH_NOCTURNO_ID 100
EXEC AFIP_GET_BATCH_NOCTURNO
*/
CREATE OR ALTER PROCEDURE dbo.AFIP_GET_BATCH_NOCTURNO_1
@pIDTaken int,
@error int
AS
BEGIN
SET NOCOUNT ON;
declare @top int
declare @top2 int
declare @iConsulta int
declare @var1 varchar(50) = 'ESTRELLA' -- 'FNAC2021' --'PAEIMPERIUM'--'SUBCAMX'--'FNAC202006A'
declare @var2 varchar(50) = 'FNAC2021'-- 'SOBLIGADOS' -- 'FNAC202105B' -- 'SOBLIGADOS'
declare @varFinal varchar(50)
/*
PARA CONTROL
declare @procesadosHoy int
declare @limiteDiario int = 120000
declare @limiteHoy int
declare @RestanHoy int
declare @TotalAProcesar int
declare @Avance money
declare @ProcesadosTotales int
declare @error int
--update consultar_afip set procesado=0,ierror=0,id_taken=0 where procesado = 1 and ierror=1
select @procesadoshoy = count(*) from consultar_afip where procesado = 1 and convert(date,fecha_proceso) = convert(date,getdate())
--select @RestanHoy= count(*) from consultar_afip where isnull(procesado,0) = 0 -- and proceso in ('SOBLIGADOS','FNAC2021')
set @RestanHoy = @limiteDiario-@procesadosHoy
select @TotalAProcesar= count(*) from consultar_afip where procesado = 0 -- proceso in ('FNAC2021')
select @ProcesadosTotales= count(*) from consultar_afip where isnull(procesado,0) = 1 and convert(date,fecha_proceso) = convert(date,getdate()) -- proceso in ('FNAC2021') and
set @limiteHoy = @limiteDiario-@procesadosHoy
set @Avance = (@ProcesadosTotales*100)/@TotalAProcesar
select @error = count(*) from consultar_afip where isnull(procesado,0) = 1 and ierror=1 --proceso in ('FNAC2021') and
select @RestanHoy as RestanHoy,@limiteDiario as limiteDiario,@procesadosHoy as ProcesadosHoy,@limiteHoy as limiteHoy,@TotalAProcesar as TotalAProcesar,@Avance as Avance,@error as Errores
select count(*) from consultar_afip where proceso = 'AA_FALLECIDOS_3' AND procesado = 0
--and substring(cuit,1,2)!='24'
select count(*) from consultar_afip where proceso = 'AA_FALLECIDOS_3' AND procesado = 1 and ierror=1
--select * from consultar_afip where proceso = 'BALANCES' AND procesado = 0 and ierror=1
-- select * from consultar_afip where proceso = 'AA_FALLECIDOS_3' AND procesado = 0 and substring(cuit,1,2)='24'
-- update consultar_afip set id_taken=0,prioridad=5 where proceso = 'AA_FALLECIDOS_3' AND procesado = 0 and substring(cuit,1,2)='24'
*/
-- select * from padrones where iscreated > getdate()-1 or ismodified > getdate()-1
-- select * from consultar_afip where procesado = 0 and ierror=0 and id_taken=80
-- select * from consultar_afip where proceso = 'AA_FALLECIDOS_3' AND procesado = 0
-- select * from consultar_afip where procesado = 0 and id_taken=100
--select * from consultar_afip where procesado = 1 and ierror=1
--update consultar_afip set procesado=0,ierror=0,id_taken=0 where procesado = 1 and ierror=1
--update consultar_afip set prioridad = 1,procesado=0,ierror=0,id_taken=0 where procesado = 0 and id_taken=300
select @top = count(*) from consultar_afip where procesado = 1 and convert(date,fecha_proceso) = convert(date,getdate())
select @iConsulta =count(*) from consultar_afip where isnull(procesado,0) = 0 and proceso IN ( @var1)
set @top2=120000-@top
--select @top as ATOP,@top2 as TOP2
-- select distinct id_taken from consultar_afip where procesado=0
--select * from consultar_afip where id_taken=100 and procesado=0
--update consultar_afip set id_taken=0 where id_taken=80 and procesado=0
if (@top2 > 250)
BEGIN
SET @TOP2 = 250
END
if (@top2 < 0)
BEGIN
SET @TOP2 = 0
END
if (@pIDTaken != 80)
begin
update top (@top2) consultar_afip set id_taken=@pIDTaken
where isnull(procesado,0) = 0 and (isnull(id_taken,0) in (0,@pIDTaken))
and idreg in (select TOP (@top2) idreg from consultar_afip where isnull(procesado,0) = 0
and (isnull(id_taken,0) in (0,@pIDTaken)) and substring(cuit,1,2) not in ('20','23','24','27')
ORDER BY prioridad,CUIT desc
)
select TOP (@top2) proceso,cuit,fecha,procesado,idreg,ierror,isnull(prioridad,10) as prioridad
from consultar_afip where isnull(procesado,0) = 0
and id_taken = @pIDTaken and substring(cuit,1,2) not in ('20','23','24','27')
ORDER BY prioridad,fecha asc,CUIT desc
end
/*
in--sert into consultar_afip (proceso,cuit,fecha,procesado,fecha_proceso,ierror)
select top 50000 'FNAC2021' AS proceso,c01_cuit as cuit, '2021-05-05' as fecha,0 as procesado,null as fecha_proceso,0 as ierror from DATOS_PERSONAS where c02_fecha_nac is null and substring(c01_cuit,1,2) in ('20','23','24','27')
AND c01_cuit NOT IN ( SELECT DISTINCT CUIT FROM CONSULTAR_AFIP WHERE PROCESO in ('FNAC202006A','FNAC2021'))
order by cuit desc
select count(*) from DATOS_PERSONAS where c02_fecha_nac is null and substring(c01_cuit,1,2) in ('20','23','24','27')
AND c01_cuit NOT IN ( SELECT DISTINCT CUIT FROM CONSULTAR_AFIP WHERE PROCESO in ('FNAC202006A','FNAC2021'))
-- update consultar_afip set procesado = 0,ierror=0 where isnull(procesado,0) = 1 and ierror=1 --proceso in ('SOBLIGADOS','FNAC2021') and
*/
END
GO
Depends On
1Used By
No items found