dbo.sp_procesos_cuit_enrichment_paepynme

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

2
Name Data Type Length Description
@id_cliente int 4
@fecha_proceso date 3

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
select * from procesos_cuit a where cliente = 2046807993 and fecha  = '2021-04-12'
and not exists (select * from  procesos_cuit_enrichment b where b.cuit = a.cuit and b.cliente= a.cliente and b.fecha_proceso = a.fecha)
select count(*) from procesos_cuit_enrichment_mas where cliente = 2046807993 and fecha_proceso = '2021-04-12'
*/

CREATE OR ALTER PROCEDURE dbo.sp_procesos_cuit_enrichment_paepynme  
@id_cliente int = 2046807993,
@fecha_proceso date = '2021-04-12'
AS
BEGIN
    SET NOCOUNT ON;

select distinct
a.Cuit as 'CUIT/CUIL', 
a.Nombre as 'Nombre',
isnull(p2.actividades,'') as 'Actividades',
a.cant_empleados as 'Cant empleados',
replace(p2.domicilio,'?',' ') as 'Domicilio',
p2.localidad as 'Localidad',
p2.provincia as 'Provincia',
p2.codpos as 'Cod Pos',
(select max(res_vtanet) from balances_contables b where b.cuit = a.cuit and estado = 'PUBLICADO' and visible = 1 and year(fecha_balance) = '2017') as 'Ventas 2017',
(select max(res_vtanet) from balances_contables b where b.cuit = a.cuit and estado = 'PUBLICADO' and visible = 1 and year(fecha_balance) = '2018') as 'Ventas 2018',
(select max(res_vtanet) from balances_contables b where b.cuit = a.cuit and estado = 'PUBLICADO' and visible = 1 and year(fecha_balance) = '2019') as 'Ventas 2019',
n.rango_desde as 'NSE desde', 
n.rango_hasta as 'NSE hasta'
from procesos_cuit_enrichment a
left join procesos_cuit_enrichment_mas p2 on p2.cliente = a.cliente and p2.Fecha_Proceso = a.Fecha_Proceso and p2.cuit = a.cuit
left join procesos_nivel_socio_economico n on n.cuit = a.cuit and n.cliente = @id_cliente and n.fecha_proceso = @fecha_proceso
left join padrones p on p.identificacion = a.cuit and p.habilitado = 1 and p.identificador in (select identificador from identificadores where country_code = 'AR')
where a.cliente = @id_cliente  
and a.fecha_proceso = @fecha_proceso
END
GO

Used By

No items found