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
CREATE OR ALTER PROCEDURE dbo.monitoreos_batch_10_cancela
@yesterday date = null
AS
BEGIN
SET NOCOUNT ON;
if (@yesterday is null) begin set @yesterday = GETDATE() - 1 end
declare @r_cuit varchar(20),@r_seccion_mantenimiento int
declare @cant1 bigint
declare @cant2 bigint
--set @cant1 = (select COUNT(*) from cendeu_cancela where CONVERT(date, created) = @yesterday)
--set @cant2 = (select COUNT(*) from cendeu_cancela where CONVERT(date, modified) = @yesterday)
--if (@cant1 > 0 or @cant2 > 0)
--BEGIN
DECLARE bn CURSOR
FOR
select distinct cuit,seccion_mantenimiento
from monitoreos
where visible = 1
and isnull(seccion_mantenimiento,10) = 10
and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento >= @yesterday)
and (fecha_desde is null or fecha_desde <= @yesterday)
--and cliente = 1299789112
-- apertura del cursor
OPEN bn
-- Lectura de la primera fila del cursor
Fetch next from bn INTO @r_cuit, @r_seccion_mantenimiento
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
--Inicio otro cursor para poder pegar por ID.
declare @r_id_cendeu int
DECLARE cendeuc CURSOR
FOR
select distinct(id_cendeu_cancela)
from cendeu_cancela
where iden = @r_cuit
and ((convert(date,created) = @yesterday and created is not null) or (convert(date,modified) = @yesterday and modified is not null))
and vigente = 1
-- apertura del cursor
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_cancela', @r_cuit, 10, @yesterday, 1, 'Bancos_cancela');
update monitoreos
set fecha_ultimo_procesamiento = @yesterday,
fecha_modificacion = @yesterday
where cuit = @r_cuit
--and cliente = 1299789112
and isnull(seccion_mantenimiento,@r_seccion_mantenimiento) = @r_seccion_mantenimiento
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
-- Cierra el cursor
CLOSE cendeuc
-- Libera los recursos del cursor
DEALLOCATE cendeuc
FETCH next from bn INTO @r_cuit,@r_seccion_mantenimiento
END
-- Cierra el cursor
CLOSE bn
-- Libera los recursos del cursor
DEALLOCATE bn
--END
END
GO
GO
CREATE OR ALTER PROCEDURE dbo.monitoreos_batch_10_cancela
@yesterday date = null
AS
BEGIN
SET NOCOUNT ON;
if (@yesterday is null) begin set @yesterday = GETDATE() - 1 end
declare @r_cuit varchar(20),@r_seccion_mantenimiento int
declare @cant1 bigint
declare @cant2 bigint
--set @cant1 = (select COUNT(*) from cendeu_cancela where CONVERT(date, created) = @yesterday)
--set @cant2 = (select COUNT(*) from cendeu_cancela where CONVERT(date, modified) = @yesterday)
--if (@cant1 > 0 or @cant2 > 0)
--BEGIN
DECLARE bn CURSOR
FOR
select distinct cuit,seccion_mantenimiento
from monitoreos
where visible = 1
and isnull(seccion_mantenimiento,10) = 10
and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento >= @yesterday)
and (fecha_desde is null or fecha_desde <= @yesterday)
--and cliente = 1299789112
-- apertura del cursor
OPEN bn
-- Lectura de la primera fila del cursor
Fetch next from bn INTO @r_cuit, @r_seccion_mantenimiento
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
--Inicio otro cursor para poder pegar por ID.
declare @r_id_cendeu int
DECLARE cendeuc CURSOR
FOR
select distinct(id_cendeu_cancela)
from cendeu_cancela
where iden = @r_cuit
and ((convert(date,created) = @yesterday and created is not null) or (convert(date,modified) = @yesterday and modified is not null))
and vigente = 1
-- apertura del cursor
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_cancela', @r_cuit, 10, @yesterday, 1, 'Bancos_cancela');
update monitoreos
set fecha_ultimo_procesamiento = @yesterday,
fecha_modificacion = @yesterday
where cuit = @r_cuit
--and cliente = 1299789112
and isnull(seccion_mantenimiento,@r_seccion_mantenimiento) = @r_seccion_mantenimiento
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
-- Cierra el cursor
CLOSE cendeuc
-- Libera los recursos del cursor
DEALLOCATE cendeuc
FETCH next from bn INTO @r_cuit,@r_seccion_mantenimiento
END
-- Cierra el cursor
CLOSE bn
-- Libera los recursos del cursor
DEALLOCATE bn
--END
END
GO
Depends On
2Used By
No items found