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
/*
Los registros de Central de Deudores que los cargan o modifican los usuarios estan en la tabla cendeu
Solo buscamos los que se dieron de alta o acutalizaron en esta tabla
Por dia, no se hacen tantas modificaciones manuales, por eso recorremos por la tabla cendeu, no por monitoreos
Los que se cargan desde el cd están en la tabla cendeu_temp
*/
/*
[monitoreos_batch_cendeu] '2018-04-16'
*/
CREATE OR ALTER PROCEDURE dbo.monitoreos_batch_cendeu_ant
@yesterday date = null
AS
BEGIN
SET NOCOUNT ON;
declare @r_id_cendeu int
declare @r_cuit varchar(20)
declare @yesterday_1 date
declare @cant1 bigint, @cant2 bigint
declare @r_situacion char(2)
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
/* */
DECLARE cec CURSOR
FOR
select iden, id_cendeu, situacion
from cendeu
where CONVERT(date, created) between @yesterday_1 and @yesterday
and vigente = 1
/*union
select iden, id_cendeu, situacion
from cendeu
where CONVERT(date, modified) between @yesterday_1 and @yesterday
and vigente = 1
*/
OPEN cec
FETCH next from cec INTO @r_cuit, @r_id_cendeu, @r_situacion
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
if (CONVERT(int,@r_situacion) = 1)
begin
FETCH next from cec INTO @r_cuit, @r_id_cendeu, @r_situacion
continue
end
if (select COUNT(*)
from monitoreos
where cuit = @r_cuit
and visible = 1
and seccion_mantenimiento = '10'
and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento >= @yesterday)
and (fecha_desde is null or fecha_desde <= @yesterday)) > 0
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)
end
FETCH next from cec INTO @r_cuit, @r_id_cendeu, @r_situacion
END
CLOSE cec
DEALLOCATE cec
END
GO
GO
/*
Los registros de Central de Deudores que los cargan o modifican los usuarios estan en la tabla cendeu
Solo buscamos los que se dieron de alta o acutalizaron en esta tabla
Por dia, no se hacen tantas modificaciones manuales, por eso recorremos por la tabla cendeu, no por monitoreos
Los que se cargan desde el cd están en la tabla cendeu_temp
*/
/*
[monitoreos_batch_cendeu] '2018-04-16'
*/
CREATE OR ALTER PROCEDURE dbo.monitoreos_batch_cendeu_ant
@yesterday date = null
AS
BEGIN
SET NOCOUNT ON;
declare @r_id_cendeu int
declare @r_cuit varchar(20)
declare @yesterday_1 date
declare @cant1 bigint, @cant2 bigint
declare @r_situacion char(2)
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
/* */
DECLARE cec CURSOR
FOR
select iden, id_cendeu, situacion
from cendeu
where CONVERT(date, created) between @yesterday_1 and @yesterday
and vigente = 1
/*union
select iden, id_cendeu, situacion
from cendeu
where CONVERT(date, modified) between @yesterday_1 and @yesterday
and vigente = 1
*/
OPEN cec
FETCH next from cec INTO @r_cuit, @r_id_cendeu, @r_situacion
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
if (CONVERT(int,@r_situacion) = 1)
begin
FETCH next from cec INTO @r_cuit, @r_id_cendeu, @r_situacion
continue
end
if (select COUNT(*)
from monitoreos
where cuit = @r_cuit
and visible = 1
and seccion_mantenimiento = '10'
and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento >= @yesterday)
and (fecha_desde is null or fecha_desde <= @yesterday)) > 0
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)
end
FETCH next from cec INTO @r_cuit, @r_id_cendeu, @r_situacion
END
CLOSE cec
DEALLOCATE cec
END
GO
Depends On
2Used By
No items found