dbo.sp_procesos_cuit_enrichment_salida_relaciones_parientes

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

3
Name Data Type Length Description
@id_cliente int 4
@fecha_proceso date 3
@cuit varchar 20

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

CREATE OR ALTER PROCEDURE dbo.sp_procesos_cuit_enrichment_salida_relaciones_parientes  
@id_cliente int = 1221411036 ,
@fecha_proceso date = '2020-09-24', 
@cuit varchar(20) = null
AS
BEGIN
    SET NOCOUNT ON;
 declare @r_cuit varchar(20) 
 declare @cantr smallint , @cantp smallint
 declare @cuit_relacionado varchar(20), @nombre_relacionado varchar(500), @cargo varchar(100), @rp char(1) 
 declare @respuesta table (  cuit varchar(20),
        nombre varchar(200),
                             cod_clae varchar(10), 
        descripcion varchar(512))
 if (@cuit is not null)
  delete procesos_cuit_enrichment_relaciones_parientes 
  where cliente = @id_cliente 
    and fecha_proceso = @fecha_proceso
    and cuit = @cuit
 else 
  delete procesos_cuit_enrichment_relaciones_parientes
  where cliente = @id_cliente 
    and fecha_proceso = @fecha_proceso
   
 if (@cuit is not null)
     DECLARE bn2 CURSOR
  FOR
  SELECT distinct cuit
    FROM procesos_cuit
  where cliente = @id_cliente
      and fecha = @fecha_proceso
    and cuit = @cuit
 else 
     DECLARE bn2 CURSOR
  FOR
  SELECT distinct cuit
    FROM procesos_cuit
  where cliente = @id_cliente
      and fecha = @fecha_proceso
      
 OPEN bn2 
 Fetch next from bn2 INTO  @r_cuit
 
 WHILE (@@FETCH_STATUS <> -1 )
 BEGIN 
   DECLARE clae2 CURSOR

   FOR
     select cuit_relacionado, nombre_relacionado, cargo, isnull(relacionado_pariente,'R') 
      from procesos_cuit_enrichment_datos_simples_socios
     where cuit = @r_cuit
     and cliente = @id_cliente
       and fecha_proceso = @fecha_proceso    
   OPEN clae2 
   FETCH next from clae2 INTO @cuit_relacionado, @nombre_relacionado, @cargo, @rp
   set @cantr = 0
   set @cantp = 0
   WHILE (@@FETCH_STATUS <> -1 )
    BEGIN
     if (@rp = 'P') 
      set @cantp = @cantp + 1
     else 
      set @cantr = @cantr + 1 
     if ((@cantr + @cantp) = 1)
     begin
      if (@rp = 'P') begin 
       insert into procesos_cuit_enrichment_relaciones_parientes
       (cliente, fecha_proceso, cuit, cuit_pariente_1, nombre_pariente_1, cargo_pariente_1) 
       values 
       (@id_cliente, @fecha_proceso, @r_cuit, @cuit_relacionado, @nombre_relacionado, @cargo)
      end else begin 
       insert into procesos_cuit_enrichment_relaciones_parientes
       (cliente, fecha_proceso, cuit, cuit_relacion_1, nombre_relacion_1, cargo_relacion_1) 
       values 
       (@id_cliente, @fecha_proceso, @r_cuit, @cuit_relacionado, @nombre_relacionado, @cargo)
      end 
     end  
     else 
     begin 
     if (@rp = 'P') 
     begin 
      if (@cantp = 1) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_pariente_1 = @cuit_relacionado,
           nombre_pariente_1 = @nombre_relacionado,
        cargo_pariente_1 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantp = 2) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_pariente_2 = @cuit_relacionado,
        nombre_pariente_2 = @nombre_relacionado,
        cargo_pariente_2 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantp = 3) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_pariente_3 = @cuit_relacionado,
        nombre_pariente_3 = @nombre_relacionado,
        cargo_pariente_3 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantp = 4) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_pariente_4 = @cuit_relacionado,
        nombre_pariente_4 = @nombre_relacionado,
        cargo_pariente_4 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantp = 5) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_pariente_5 = @cuit_relacionado,
        nombre_pariente_5 = @nombre_relacionado,
        cargo_pariente_5 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantp = 6) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_pariente_6 = @cuit_relacionado,
        nombre_pariente_6 = @nombre_relacionado,
        cargo_pariente_6 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantp = 7) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_pariente_7 = @cuit_relacionado,
        nombre_pariente_7 = @nombre_relacionado,
        cargo_pariente_7 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantp = 8) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_pariente_8 = @cuit_relacionado,
        nombre_pariente_8 = @nombre_relacionado,
        cargo_pariente_8 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantp = 9) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_pariente_9 = @cuit_relacionado,
        nombre_pariente_9 = @nombre_relacionado,
        cargo_pariente_9 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantp = 10) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_pariente_10 = @cuit_relacionado,
        nombre_pariente_10 = @nombre_relacionado,
        cargo_pariente_10 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
     end 
     else 
     begin 
      if (@cantr = 1) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_relacion_1 = @cuit_relacionado,
           nombre_relacion_1 = @nombre_relacionado,
        cargo_relacion_1 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantr = 2) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_relacion_2 = @cuit_relacionado,
        nombre_relacion_2 = @nombre_relacionado,
        cargo_relacion_2 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantr = 3) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_relacion_3 = @cuit_relacionado,
        nombre_relacion_3 = @nombre_relacionado,
        cargo_relacion_3 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantr = 4) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_relacion_4 = @cuit_relacionado,
        nombre_relacion_4 = @nombre_relacionado,
        cargo_relacion_4 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantr = 5) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_relacion_5 = @cuit_relacionado,
        nombre_relacion_5 = @nombre_relacionado,
        cargo_relacion_5 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantr = 6) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_relacion_6 = @cuit_relacionado,
        nombre_relacion_6 = @nombre_relacionado,
        cargo_relacion_6 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantr = 7) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_relacion_7 = @cuit_relacionado,
        nombre_relacion_7 = @nombre_relacionado,
        cargo_relacion_7 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantr = 8) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_relacion_8 = @cuit_relacionado,
        nombre_relacion_8 = @nombre_relacionado,
        cargo_relacion_8 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantr = 9) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_relacion_9 = @cuit_relacionado,
        nombre_relacion_9 = @nombre_relacionado,
        cargo_relacion_9 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
      if (@cantr = 10) 
       update procesos_cuit_enrichment_relaciones_parientes
       set cuit_relacion_10 = @cuit_relacionado,
        nombre_relacion_10 = @nombre_relacionado,
        cargo_relacion_10 = @cargo
       where cliente = @id_cliente
         and fecha_proceso = @fecha_proceso
         and cuit = @r_cuit 
     end
     end  
     FETCH next from clae2 INTO @cuit_relacionado, @nombre_relacionado, @cargo, @rp
   END
   CLOSE clae2
   DEALLOCATE clae2 
   Fetch next from bn2 INTO  @r_cuit
  END 
  CLOSE bn2
  DEALLOCATE bn2
  select * from procesos_cuit_enrichment_relaciones_parientes 
  where cliente = @id_cliente
  and fecha_proceso = @fecha_proceso
END 
   
GO

Used By

No items found