Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
3| Name | Data Type | Length | Description |
|---|---|---|---|
| @cliente | int | 4 | |
| @fecha_proceso | date | 3 | |
| @retomar | char | 1 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.sp_procesos_nivel_socio_economico_escliente
@cliente int = '263625984',
@fecha_proceso date = '2018-08-06',
@retomar char(1) = 'N'
AS
BEGIN
SET NOCOUNT ON;
declare @id_padron int,
@nombre varchar(100),
@identificador varchar(10),
@cuit varchar(20),
@rango_desde decimal(20,2),
@rango_hasta decimal(20,2),
@comex_importaciones decimal(20,2),
@comex_exportaciones decimal(20,2),
@facturacion decimal(20,2),
@es_cliente int ,
@es_cliente_sn bit
declare @fec_periodo_minimo varchar(11),
@periodo_minimo varchar(7)
set @fec_periodo_minimo = dateadd(MM, -23,getdate())
set @periodo_minimo = convert(varchar(4),DATEPART(yyyy,@fec_periodo_minimo))+right('0'+convert(varchar(2),DATEPART(mm,@fec_periodo_minimo)),2)
--> Inicio
DECLARE C_padron CURSOR FOR
select distinct /* top 10 */
r.id_padron,
r.nombre,
r.cuit
from procesos_nivel_socio_economico_respuesta r
where cliente = @cliente
and fecha_proceso = @fecha_proceso
OPEN C_Padron
FETCH NEXT FROM C_Padron INTO @id_padron,
@nombre,
@cuit
WHILE @@fetch_status = 0
BEGIN
--> Es cliente
set @fec_periodo_minimo = dateadd(MM, -23,getdate())
set @periodo_minimo = convert(varchar(4),DATEPART(yyyy,@fec_periodo_minimo))+right('0'+convert(varchar(2),DATEPART(mm,@fec_periodo_minimo)),2)
set @es_cliente = (select count(*) from cendeu_temp where convert(int,codigo_ent) in (285) and iden = @cuit and vigente = 1 and fec_inf >= @periodo_minimo)
if(@es_cliente = 0)
begin
set @es_cliente = (select count(*) from cendeu where convert(int,codigo_ent) in (285) and iden = @cuit and vigente = 1 and fec_inf >= @periodo_minimo)
end
set @es_cliente_sn = 0
if (@es_cliente > 0) set @es_cliente_sn = 1
update procesos_nivel_socio_economico set es_cliente = @es_cliente_sn where cuit = @cuit
FETCH NEXT FROM C_Padron INTO @id_padron,
@nombre,
@cuit
END
CLOSE C_Padron
DEALLOCATE C_Padron
END
GO
GO
CREATE OR ALTER PROCEDURE dbo.sp_procesos_nivel_socio_economico_escliente
@cliente int = '263625984',
@fecha_proceso date = '2018-08-06',
@retomar char(1) = 'N'
AS
BEGIN
SET NOCOUNT ON;
declare @id_padron int,
@nombre varchar(100),
@identificador varchar(10),
@cuit varchar(20),
@rango_desde decimal(20,2),
@rango_hasta decimal(20,2),
@comex_importaciones decimal(20,2),
@comex_exportaciones decimal(20,2),
@facturacion decimal(20,2),
@es_cliente int ,
@es_cliente_sn bit
declare @fec_periodo_minimo varchar(11),
@periodo_minimo varchar(7)
set @fec_periodo_minimo = dateadd(MM, -23,getdate())
set @periodo_minimo = convert(varchar(4),DATEPART(yyyy,@fec_periodo_minimo))+right('0'+convert(varchar(2),DATEPART(mm,@fec_periodo_minimo)),2)
--> Inicio
DECLARE C_padron CURSOR FOR
select distinct /* top 10 */
r.id_padron,
r.nombre,
r.cuit
from procesos_nivel_socio_economico_respuesta r
where cliente = @cliente
and fecha_proceso = @fecha_proceso
OPEN C_Padron
FETCH NEXT FROM C_Padron INTO @id_padron,
@nombre,
@cuit
WHILE @@fetch_status = 0
BEGIN
--> Es cliente
set @fec_periodo_minimo = dateadd(MM, -23,getdate())
set @periodo_minimo = convert(varchar(4),DATEPART(yyyy,@fec_periodo_minimo))+right('0'+convert(varchar(2),DATEPART(mm,@fec_periodo_minimo)),2)
set @es_cliente = (select count(*) from cendeu_temp where convert(int,codigo_ent) in (285) and iden = @cuit and vigente = 1 and fec_inf >= @periodo_minimo)
if(@es_cliente = 0)
begin
set @es_cliente = (select count(*) from cendeu where convert(int,codigo_ent) in (285) and iden = @cuit and vigente = 1 and fec_inf >= @periodo_minimo)
end
set @es_cliente_sn = 0
if (@es_cliente > 0) set @es_cliente_sn = 1
update procesos_nivel_socio_economico set es_cliente = @es_cliente_sn where cuit = @cuit
FETCH NEXT FROM C_Padron INTO @id_padron,
@nombre,
@cuit
END
CLOSE C_Padron
DEALLOCATE C_Padron
END
GO
Used By
No items found