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_10_new '2017-07-17'
--select * from monitoreos_resultados where tabla = 'cendeu1'
--delete from monitoreos_resultados where tabla = 'cendeu1'
--select * from monitoreos_resultados where CONVERT(date,fecha) = '2018-03-07' and tipo_NOvedad = 'Bancos' order by tabla
CREATE OR ALTER PROCEDURE dbo.monitoreos_batch_10_cendeu
@yesterday date = null
AS
BEGIN
SET NOCOUNT ON;
declare @r_id_cendeu int
declare @r_cuit varchar(20)
declare @yesterday_1 date
declare @cantidad bigint = 0
if (@yesterday is null) begin set @yesterday = GETDATE() - 1 end
set @yesterday_1 = @yesterday
/* Cuando se quiere desde una fecha anterior hasta hoy, agregar este set: */
if (@yesterday = '2018-03-07')
begin
set @yesterday_1 = '2018-02-01'
end
/* */
-- Busca todos los cuits que estan en monitoreo, para Central de Deudores
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)
order by cuit
OPEN bn
Fetch next from bn INTO @r_cuit
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
set @cantidad = @cantidad + 1
--if (@cantidad > 10) begin break end
-- 1) Busca en cendeu ese cuit que esta en monitoreo
DECLARE cendeuc CURSOR
FOR
select distinct(id_cendeu)
from cendeu
where iden = @r_cuit
and vigente = 1
and ((convert(date,created) between @yesterday_1 and @yesterday and created is not null) or (convert(date,modified) between @yesterday_1 and @yesterday and modified is not null))
and CONVERT(int,situacion) > 1
OPEN cendeuc
FETCH next from cendeuc INTO @r_id_cendeu
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
insert into monitoreos_resultados
(id_tabla, tabla, cuit, seccion_mantenimiento, fecha, novedad, tipo_novedad)
values (@r_id_cendeu, 'cendeu', @r_cuit, 10, @yesterday, 1, 'Bancos');
update monitoreos
set fecha_ultimo_procesamiento = @yesterday,
fecha_modificacion = @yesterday
where cuit= @r_cuit
and seccion_mantenimiento = 10
and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento >= @yesterday)
and (fecha_desde is null or fecha_desde <= @yesterday)
FETCH next from cendeuc INTO @r_id_cendeu
END
CLOSE cendeuc
DEALLOCATE cendeuc
-- 2) Busca en cendeu_temp ese cuit que esta en monitoreo
DECLARE cendeuc2 CURSOR
FOR
select distinct(id_cendeu)
from cendeu_temp
where iden = @r_cuit
and vigente = 1
and ((convert(date,created) between @yesterday_1 and @yesterday and created is not null) or (convert(date,modified) between @yesterday_1 and @yesterday and modified is not null))
and CONVERT(int,situacion) > 1
OPEN cendeuc2
FETCH next from cendeuc2 INTO @r_id_cendeu
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
insert into monitoreos_resultados
(id_tabla, tabla, cuit, seccion_mantenimiento, fecha, novedad, tipo_novedad)
values (@r_id_cendeu, 'cendeu_temp', @r_cuit, 10, @yesterday, 1, 'Bancos');
update monitoreos
set fecha_ultimo_procesamiento = @yesterday,
fecha_modificacion = @yesterday
where cuit= @r_cuit
and seccion_mantenimiento = 10
and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento >= @yesterday)
and (fecha_desde is null or fecha_desde <= @yesterday)
FETCH next from cendeuc2 INTO @r_id_cendeu
END
CLOSE cendeuc2
DEALLOCATE cendeuc2
-- Sigue recorriendo la tabla monitoreos
FETCH next from bn INTO @r_cuit
END
CLOSE bn
DEALLOCATE bn
END
GO
GO
--exec monitoreos_batch_10_new '2017-07-17'
--select * from monitoreos_resultados where tabla = 'cendeu1'
--delete from monitoreos_resultados where tabla = 'cendeu1'
--select * from monitoreos_resultados where CONVERT(date,fecha) = '2018-03-07' and tipo_NOvedad = 'Bancos' order by tabla
CREATE OR ALTER PROCEDURE dbo.monitoreos_batch_10_cendeu
@yesterday date = null
AS
BEGIN
SET NOCOUNT ON;
declare @r_id_cendeu int
declare @r_cuit varchar(20)
declare @yesterday_1 date
declare @cantidad bigint = 0
if (@yesterday is null) begin set @yesterday = GETDATE() - 1 end
set @yesterday_1 = @yesterday
/* Cuando se quiere desde una fecha anterior hasta hoy, agregar este set: */
if (@yesterday = '2018-03-07')
begin
set @yesterday_1 = '2018-02-01'
end
/* */
-- Busca todos los cuits que estan en monitoreo, para Central de Deudores
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)
order by cuit
OPEN bn
Fetch next from bn INTO @r_cuit
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
set @cantidad = @cantidad + 1
--if (@cantidad > 10) begin break end
-- 1) Busca en cendeu ese cuit que esta en monitoreo
DECLARE cendeuc CURSOR
FOR
select distinct(id_cendeu)
from cendeu
where iden = @r_cuit
and vigente = 1
and ((convert(date,created) between @yesterday_1 and @yesterday and created is not null) or (convert(date,modified) between @yesterday_1 and @yesterday and modified is not null))
and CONVERT(int,situacion) > 1
OPEN cendeuc
FETCH next from cendeuc INTO @r_id_cendeu
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
insert into monitoreos_resultados
(id_tabla, tabla, cuit, seccion_mantenimiento, fecha, novedad, tipo_novedad)
values (@r_id_cendeu, 'cendeu', @r_cuit, 10, @yesterday, 1, 'Bancos');
update monitoreos
set fecha_ultimo_procesamiento = @yesterday,
fecha_modificacion = @yesterday
where cuit= @r_cuit
and seccion_mantenimiento = 10
and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento >= @yesterday)
and (fecha_desde is null or fecha_desde <= @yesterday)
FETCH next from cendeuc INTO @r_id_cendeu
END
CLOSE cendeuc
DEALLOCATE cendeuc
-- 2) Busca en cendeu_temp ese cuit que esta en monitoreo
DECLARE cendeuc2 CURSOR
FOR
select distinct(id_cendeu)
from cendeu_temp
where iden = @r_cuit
and vigente = 1
and ((convert(date,created) between @yesterday_1 and @yesterday and created is not null) or (convert(date,modified) between @yesterday_1 and @yesterday and modified is not null))
and CONVERT(int,situacion) > 1
OPEN cendeuc2
FETCH next from cendeuc2 INTO @r_id_cendeu
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
insert into monitoreos_resultados
(id_tabla, tabla, cuit, seccion_mantenimiento, fecha, novedad, tipo_novedad)
values (@r_id_cendeu, 'cendeu_temp', @r_cuit, 10, @yesterday, 1, 'Bancos');
update monitoreos
set fecha_ultimo_procesamiento = @yesterday,
fecha_modificacion = @yesterday
where cuit= @r_cuit
and seccion_mantenimiento = 10
and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento >= @yesterday)
and (fecha_desde is null or fecha_desde <= @yesterday)
FETCH next from cendeuc2 INTO @r_id_cendeu
END
CLOSE cendeuc2
DEALLOCATE cendeuc2
-- Sigue recorriendo la tabla monitoreos
FETCH next from bn INTO @r_cuit
END
CLOSE bn
DEALLOCATE bn
END
GO
Depends On
3Used By
No items found