dbo.backend_busqueda_padron_asociativa_2da_fase

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

9
Name Data Type Length Description
@p_razon_social varchar 152
@p_domicilio varchar 514
@p_localidad varchar 52
@p_provincia varchar 52
@p_nombre varchar 182
@p_fecha_nac varchar 152
@p_profesion varchar 152
@p_cargo varchar 152
@p_cuit_sociedad varchar 50

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: <Samuel Gonzalez>
-- Create date: <03 Ago 2017>
-- Description: <Buscador padrón asociativo, 
-- busca cuits en padrón por:
-- sociedades:
-- (razon_social, provincia y localidad) o por (razon_social y fecha cosntitución)
-- personas:
-- 1. nombre, domicilio, fecha_nacimiento
-- 2. nombre, domicilio, profesion
-- 3. nombre, domicilio, estado_civil
-- 4. nombre, cargo, razon_social
-- 5. nombre, cargo, razon_social, fecha_nacimiento
-- 6. nombre, cargo, razon_social, profesion
-- 7. nombre, provincia, localidad, profesion, fecha_nacimiento 
--     8. nombre, provincia, localidad, cargo, fecha_nacimiento 
--     9. nombre, profesion, cargo, fecha_nacimiento

-- Esta es la segunda fase de la búsqueda en donde las personas son buscadas con un CONTAINS para evaluar todas las posibles combinaciones de nombres.
-- =============================================
CREATE OR ALTER PROCEDURE dbo.backend_busqueda_padron_asociativa_2da_fase 
 -- Add the parameters for the stored procedure here
 @p_razon_social    varchar(152),  -- 1
 @p_domicilio       varchar(514),  -- 2
 @p_localidad       varchar(52),  -- 3
 @p_provincia       varchar(52),  -- 4
 @p_nombre          varchar(182), -- 5
 @p_fecha_nac       varchar(152), -- 6
 @p_profesion       varchar(152), -- 7
 @p_cargo     varchar(152), -- 8
 @p_cuit_sociedad   varchar(50)   -- 9
AS
BEGIN
 SET NOCOUNT ON;
 DECLARE @multiplicidad int = 0

 if (@p_razon_social is not null) and (@p_razon_social != '') 
 and ((@p_nombre is null) or (@p_nombre != '')) -- ES UNA BUSQUEDA PARA SOCIEDAD -------------------
 begin
  if (@p_localidad is not null) and (@p_localidad != '')
  and (@p_provincia is not null) and (@p_provincia != '')
  begin
   select distinct d.cuit from domicilios_todos d
   inner join  padrones p on (d.cuit = p.identificacion)
   where (CONTAINS(p.nombre_persona, @p_razon_social)) and (d.loc_nombre =  @p_localidad) and (d.prv_nombre =  @p_provincia)
  end
 end
 else if (@p_nombre is not null) and (@p_nombre != '') -- ES UNA BUSQUEDA PARA PERSONA --------------
 begin
  if (@p_domicilio is not null) and (@p_domicilio != '')
  begin
   if (@p_fecha_nac is not null) and (@p_fecha_nac != '')
   begin
    select distinct d.c01_cuit as cuit from datos_personas d
    inner join 
     (select distinct cuit from domicilios_todos dt 
     inner join padrones p on (p.identificacion = dt.cuit)
     where (CONTAINS(p.nombre_persona , @p_nombre)) and (dt.domicilio =  @p_domicilio)) busqueda
    on (d.c01_cuit = busqueda.cuit)
    where (d.c02_fecha_nac =  @p_fecha_nac)
   end
   else if (@p_profesion is not null) and (@p_profesion != '')
   begin
    select distinct d.c01_cuit as cuit from datos_personas d
    inner join 
     (select distinct cuit from domicilios_todos dt 
     inner join padrones p on (p.identificacion = dt.cuit)
     where (CONTAINS(p.nombre_persona , @p_nombre)) and (dt.domicilio =  @p_domicilio)) busqueda
    on (d.c01_cuit = busqueda.cuit)
    inner join profesiones pr on (pr.pro_codigo = d.pro_codigo_profesion)
    where (pr.pro_nombre =  @p_profesion)
   end
  end
  else if (@p_cargo is not null) and (@p_cargo != '') 
  and (@p_cuit_sociedad is not null) and (@p_cuit_sociedad != '')
  begin
   if (@p_fecha_nac is not null) and (@p_fecha_nac != '')
   begin
                select distinct identificacion as cuit from padrones p
                inner join DATOS_PERSONAS d on (d.c01_cuit = p.identificacion)
    inner join relaciones r on (r.cuita = p.identificacion)
    inner join tipo_vinculaciones t on (t.id_tipo_vinculacion = r.id_tipo_relacion)
    where (CONTAINS(p.nombre_persona , @p_nombre)) 
    and (r.cuitb = @p_cuit_sociedad) and (t.nombre = @p_cargo) and (d.c02_fecha_nac = @p_fecha_nac)
                
                union

                select distinct identificacion as cuit from padrones p
                inner join DATOS_PERSONAS d on (d.c01_cuit = p.identificacion)
    inner join relaciones r on (r.cuitb = p.identificacion)
    inner join tipo_vinculaciones t on (t.id_tipo_vinculacion = r.id_tipo_relacion)
    where (CONTAINS(p.nombre_persona , @p_nombre)) 
    and (r.cuita = @p_cuit_sociedad) and (t.nombre = @p_cargo) and (d.c02_fecha_nac = @p_fecha_nac)

                union

                select distinct identificacion as cuit from padrones p
                inner join DATOS_PERSONAS d on (d.c01_cuit = p.identificacion)
    inner join socios s on (s.c01_cuit_soc = p.identificacion)
    inner join CARGOS c on (c.car_codigo = s.car_codigo)
    where (CONTAINS(p.nombre_persona , @p_nombre)) 
    and (s.c01_cuit = @p_cuit_sociedad) and (c.car_nombre = @p_cargo) and (d.c02_fecha_nac = @p_fecha_nac)
   end
   else if (@p_profesion is not null) and (@p_profesion != '')
   begin
       select distinct identificacion as cuit from padrones p
                inner join DATOS_PERSONAS d on (d.c01_cuit = p.identificacion)
                inner join profesiones pr on (pr.pro_codigo = d.pro_codigo_profesion)
    inner join relaciones r on (r.cuita = p.identificacion)
    inner join tipo_vinculaciones t on (t.id_tipo_vinculacion = r.id_tipo_relacion)
    where (CONTAINS(p.nombre_persona , @p_nombre)) 
    and (r.cuitb = @p_cuit_sociedad) and (t.nombre = @p_cargo) and (pr.pro_nombre = @p_profesion)
                
                union

                select distinct identificacion as cuit from padrones p
                inner join DATOS_PERSONAS d on (d.c01_cuit = p.identificacion)
                inner join profesiones pr on (pr.pro_codigo = d.pro_codigo_profesion)
    inner join relaciones r on (r.cuitb = p.identificacion)
    inner join tipo_vinculaciones t on (t.id_tipo_vinculacion = r.id_tipo_relacion)
    where (CONTAINS(p.nombre_persona , @p_nombre)) 
    and (r.cuita = @p_cuit_sociedad) and (t.nombre = @p_cargo) and (pr.pro_nombre = @p_profesion)

                union

                select distinct identificacion as cuit from padrones p
                inner join DATOS_PERSONAS d on (d.c01_cuit = p.identificacion)
                inner join profesiones pr on (pr.pro_codigo = d.pro_codigo_profesion)
    inner join socios s on (s.c01_cuit_soc = p.identificacion)
    inner join CARGOS c on (c.car_codigo = s.car_codigo)
    where (CONTAINS(p.nombre_persona , @p_nombre)) 
    and (s.c01_cuit = @p_cuit_sociedad) and (c.car_nombre = @p_cargo) and (pr.pro_nombre = @p_profesion)
   end
   else
   begin
    select distinct identificacion as cuit from padrones p
    inner join relaciones r on (r.cuita = p.identificacion)
    inner join tipo_vinculaciones t on (t.id_tipo_vinculacion = r.id_tipo_relacion)
    where (CONTAINS(p.nombre_persona , @p_nombre)) 
    and (r.cuitb = @p_cuit_sociedad) and (t.nombre = @p_cargo)
                
                union

                select distinct identificacion as cuit from padrones p
    inner join relaciones r on (r.cuitb = p.identificacion)
    inner join tipo_vinculaciones t on (t.id_tipo_vinculacion = r.id_tipo_relacion)
    where (CONTAINS(p.nombre_persona , @p_nombre)) 
    and (r.cuita = @p_cuit_sociedad) and (t.nombre = @p_cargo)

                union

                select distinct identificacion as cuit from padrones p
    inner join socios s on (s.c01_cuit_soc = p.identificacion)
    inner join CARGOS c on (c.car_codigo = s.car_codigo)
    where (CONTAINS(p.nombre_persona , @p_nombre)) 
    and (s.c01_cuit = @p_cuit_sociedad) and (c.car_nombre = @p_cargo)
      end
     end
        else if (@p_provincia is not null) and (@p_provincia != '') 
  and (@p_localidad is not null) and (@p_localidad != '')
        and (@p_profesion is not null) and (@p_profesion != '')
        and (@p_fecha_nac is not null) and (@p_fecha_nac != '')
        begin
            select distinct identificacion as cuit from padrones p
            inner join domicilios_todos d on (d.cuit = p.identificacion)
            inner join datos_personas dp on (dp.c01_cuit = p.identificacion)
            inner join profesiones pr on (pr.pro_codigo = dp.pro_codigo_profesion)
            where (CONTAINS(p.nombre_persona , @p_nombre))
            and (d.prv_nombre = @p_provincia) and (d.loc_nombre = @p_localidad)
            and (pr.pro_nombre = @p_profesion) and (dp.c02_fecha_nac = @p_fecha_nac)
        end
 end
END

GO

Used By

No items found