dbo.arregla_integrantes_sociedades

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

-- exec arregla_integrantes_sociedades

CREATE OR ALTER PROCEDURE dbo.arregla_integrantes_sociedades

AS


BEGIN
    SET NOCOUNT ON;
declare @id_cliente int = 7777
declare @fecha_proceso date = convert(date,getdate())
declare @cuit_procesar varchar(20)
declare @nombre_integrante varchar(500)
DECLARE ProdInfo CURSOR FOR

/*
procesos_cuit_enrichment
*/


select cuit from screening_prov where cliente = 7777 and created > '2018-03-21' and cuit like '3%'

OPEN ProdInfo

FETCH NEXT FROM ProdInfo INTO @cuit_procesar

WHILE @@fetch_status = 0

 BEGIN
 declare @cantidad_integrantes int
 declare @cuit_integrante VARCHAR(20)
 declare @cantidad_integrantes_iguales int
  set @cantidad_integrantes = (select count(nombre_integrante) from sociedades_constituciones where documento_soc = @cuit_procesar and nombre_integrante != '' )
  if(@cantidad_integrantes > 0)
   begin
    DECLARE cursorIntegrantes CURSOR FOR
    select nombre_integrante from sociedades_constituciones where documento_soc = @cuit_procesar  and nombre_integrante != ''
    OPEN cursorIntegrantes
     FETCH NEXT FROM cursorIntegrantes INTO @nombre_integrante
    
    WHILE @@fetch_status = 0
     BEGIN
     declare @nombre_limpio varchar(500) = @nombre_integrante
     if(CHARINDEX(@nombre_integrante,' ') > 0)
      begin
      set @nombre_integrante = 'NEAR('+Replace(@nombre_integrante,' ',',') + ')'
      end
     else
      begin
      set @nombre_integrante = QUOTENAME(@nombre_integrante,'"')
      end
     set @cantidad_integrantes_iguales  = (select count(identificacion) from padrones where contains(nombre_persona,@nombre_integrante) and habilitado = 1)
     if(@cantidad_integrantes_iguales = 1)
      begin
       set @cuit_integrante  = (select identificacion from padrones where contains(nombre_persona,@nombre_integrante) and habilitado = 1)
       --select '1',@cuit_integrante,@nombre_integrante
       update sociedades_constituciones set cuit_int = @cuit_integrante, marcado = 1 where nombre_integrante = @nombre_limpio
      -- Insert en tabla temporal.
      --insert into temp_integrantes_de_sociedades (cuit_procesar,identificacion,nombre_integrante) values (@cuit_procesar,@cuit_integrante,@nombre_integrante)
      end
     else
      begin
      set @cantidad_integrantes_iguales  = (select count(identificacion) from padrones where nombre_persona like '%'+@nombre_integrante+'%' and habilitado = 1)
      if(@cantidad_integrantes_iguales = 1)
       begin
        set @cuit_integrante  = (select identificacion from padrones where nombre_persona like '%'+@nombre_integrante+'%' and habilitado = 1)
        --select '2',@cuit_integrante,@nombre_integrante
        update sociedades_constituciones set cuit_int = @cuit_integrante, marcado = 1 where nombre_integrante = @nombre_limpio
       -- Insert en tabla temporal.
       --insert into temp_integrantes_de_sociedades (cuit_procesar,identificacion,nombre_integrante) values (@cuit_procesar,@cuit_integrante,@nombre_integrante)
       end
      end
     FETCH NEXT FROM cursorIntegrantes INTO @nombre_integrante
     END
    CLOSE cursorIntegrantes
    DEALLOCATE cursorIntegrantes
   end
   
  FETCH NEXT FROM ProdInfo INTO @cuit_procesar
 END

CLOSE ProdInfo

DEALLOCATE ProdInfo
END

GO

Used By

No items found