Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
2| Name | Data Type | Length | Description |
|---|---|---|---|
| @cliente | int | 4 | |
| @fecha_proceso | date | 3 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.sp_procesos_cuit_enrichment_simples_filtros
@cliente int = 2254875,
@fecha_proceso date = '2018-10-12'
AS
BEGIN
SET NOCOUNT ON;
declare @visible bit
declare @cuit varchar(20)
declare @id int
declare @empleados_cuit table (
hombres decimal(10,2),
mujeres decimal(10,2),
total decimal(10,2),
fecha varchar(10))
declare @cant_empleados int = 0
DECLARE C_padron CURSOR FOR
select ID, cuit
from procesos_cuit_enrichment_datos_simples
where cliente = @cliente and Fecha_Proceso = @fecha_proceso
and
(prv_nombre in (
'AMBA OESTE'
,'CAPITAL Y GBA NORTE'
,'CIUDAD DE BUENOS AIRES'
,'CIUDAD AUTONOMA DE BUENOS AIRES'
,'AMBA SUR'
,'CIUDAD AUTONOMA BUENOS AIRES'
,'BUENOS AIRES')
or
prv_nombre2 in (
'AMBA OESTE'
,'CAPITAL Y GBA NORTE'
,'CIUDAD DE BUENOS AIRES'
,'CIUDAD AUTONOMA DE BUENOS AIRES'
,'AMBA SUR'
,'CIUDAD AUTONOMA BUENOS AIRES'
,'BUENOS AIRES'))
and fecha_defuncion is null
and email is not null
and (visible is null or visible = 0)
OPEN C_Padron
FETCH NEXT FROM C_Padron INTO @id, @cuit
WHILE @@fetch_status = 0
BEGIN
set @visible = 1
if (select COUNT(*) from cendeu_temp where iden = @cuit and fec_inf >= '2018-02' and CONVERT(int, situacion) > 1) > 0
begin
set @visible = 0
end
if (@visible = 1 )
begin
if (select COUNT(*) from cendeu where iden = @cuit and fec_inf >= '2018-02' and CONVERT(int, situacion) > 1) > 0
begin
set @visible = 0
end
end
if (@visible = 1 )
begin
if (select COUNT(*) from ChequesBCRA where cuit_firmante = @cuit and fecha_rechazo >= '2018-02-01') > 0
begin
set @visible = 0
end
end
if (@visible = 1 )
begin
if (select COUNT(*) from juicios
left join tiempo_causas on tiempo_causas.cau_codigo = iif(isnull(juicios.id_tipo_causa,'') = '', juicios.cau_codigo, juicios.id_tipo_causa)
where cuit_demandado = @cuit
and juicios.fecha_causa > (GETDATE()-(isnull(tiempo,5)*365))
and (isnull(juicios.id_tipo_causa,'') in (select id_tipo_causa from tipos_causas where grupo = 'CYQ')
or ISNULL(juicios.cau_codigo,'') in (select id_tipo_causa from tipos_causas where grupo = 'CYQ')
)
) > 0
begin
set @visible = 0
end
end
set @cant_empleados = null
if (@visible = 1)
begin
set @cant_empleados = 0
insert into @empleados_cuit
exec obtener_empleados @cuit
set @cant_empleados = (select total from @empleados_cuit)
delete from @empleados_cuit
end
update procesos_cuit_enrichment_datos_simples
set visible = @visible,
cant_empleados = @cant_empleados
where id = @id
FETCH NEXT FROM C_Padron INTO @id, @cuit
END
END
GO
GO
CREATE OR ALTER PROCEDURE dbo.sp_procesos_cuit_enrichment_simples_filtros
@cliente int = 2254875,
@fecha_proceso date = '2018-10-12'
AS
BEGIN
SET NOCOUNT ON;
declare @visible bit
declare @cuit varchar(20)
declare @id int
declare @empleados_cuit table (
hombres decimal(10,2),
mujeres decimal(10,2),
total decimal(10,2),
fecha varchar(10))
declare @cant_empleados int = 0
DECLARE C_padron CURSOR FOR
select ID, cuit
from procesos_cuit_enrichment_datos_simples
where cliente = @cliente and Fecha_Proceso = @fecha_proceso
and
(prv_nombre in (
'AMBA OESTE'
,'CAPITAL Y GBA NORTE'
,'CIUDAD DE BUENOS AIRES'
,'CIUDAD AUTONOMA DE BUENOS AIRES'
,'AMBA SUR'
,'CIUDAD AUTONOMA BUENOS AIRES'
,'BUENOS AIRES')
or
prv_nombre2 in (
'AMBA OESTE'
,'CAPITAL Y GBA NORTE'
,'CIUDAD DE BUENOS AIRES'
,'CIUDAD AUTONOMA DE BUENOS AIRES'
,'AMBA SUR'
,'CIUDAD AUTONOMA BUENOS AIRES'
,'BUENOS AIRES'))
and fecha_defuncion is null
and email is not null
and (visible is null or visible = 0)
OPEN C_Padron
FETCH NEXT FROM C_Padron INTO @id, @cuit
WHILE @@fetch_status = 0
BEGIN
set @visible = 1
if (select COUNT(*) from cendeu_temp where iden = @cuit and fec_inf >= '2018-02' and CONVERT(int, situacion) > 1) > 0
begin
set @visible = 0
end
if (@visible = 1 )
begin
if (select COUNT(*) from cendeu where iden = @cuit and fec_inf >= '2018-02' and CONVERT(int, situacion) > 1) > 0
begin
set @visible = 0
end
end
if (@visible = 1 )
begin
if (select COUNT(*) from ChequesBCRA where cuit_firmante = @cuit and fecha_rechazo >= '2018-02-01') > 0
begin
set @visible = 0
end
end
if (@visible = 1 )
begin
if (select COUNT(*) from juicios
left join tiempo_causas on tiempo_causas.cau_codigo = iif(isnull(juicios.id_tipo_causa,'') = '', juicios.cau_codigo, juicios.id_tipo_causa)
where cuit_demandado = @cuit
and juicios.fecha_causa > (GETDATE()-(isnull(tiempo,5)*365))
and (isnull(juicios.id_tipo_causa,'') in (select id_tipo_causa from tipos_causas where grupo = 'CYQ')
or ISNULL(juicios.cau_codigo,'') in (select id_tipo_causa from tipos_causas where grupo = 'CYQ')
)
) > 0
begin
set @visible = 0
end
end
set @cant_empleados = null
if (@visible = 1)
begin
set @cant_empleados = 0
insert into @empleados_cuit
exec obtener_empleados @cuit
set @cant_empleados = (select total from @empleados_cuit)
delete from @empleados_cuit
end
update procesos_cuit_enrichment_datos_simples
set visible = @visible,
cant_empleados = @cant_empleados
where id = @id
FETCH NEXT FROM C_Padron INTO @id, @cuit
END
END
GO
Depends On
8Used By
No items found