dbo.api_padrones_2024

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

4
Name Data Type Length Description
@p_taxid varchar 50
@name varchar 100
@country_code varchar 2
@max_rows int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: AGB
-- Create date: 2023-06-21
-- Description: Búsqueda de Padrón completo
-- =============================================

/*

api_padrones '20134934864',null,'AR',30

exec api_padrones null,'VAZQUEZ ERNESTO','AR',50
exec api_padrones null,'VILLARROEL',NULL,10

exec api_padrones '22222222','"VILLARROEL"','AR',10

exec api_padrones '336165009','VILLARROEL DIEGO',NULL,10

exec api_padrones null,'SORIA MARIA INES','AR',10
exec api_padrones 'RUEDA FERNANDEZ ALMA PATRICIA',null,null,10

select top 2 * from padrones where identificador = 'CURP'



select * from padrones where identificacion = '336165009'
*/

/*
exec [api_padrones_2024] 'soria maria ines',null,'AR',30
exec [api_padrones_2024] '99999999999',null,'AR',30
exec [api_padrones_2024] '20892565',null,'AR',30
exec [api_padrones_2024] 'R',null,'AR',30
*/

CREATE OR ALTER PROCEDURE dbo.api_padrones_2024
@p_taxid varchar(50) = null,
@name varchar(100) = null,
@country_code varchar(2) = NULL,
@max_rows int = 30
AS
BEGIN
 SET NOCOUNT ON;
 if (@country_code!='AR') set @country_code = null 

 select @p_taxid = ltrim(rtrim(@p_taxid))
 select @name = ltrim(rtrim(@name))
 
 IF (isnull(@p_taxid,'') != '') --> Prioriza busqueda por lo que viene en el campo taxid
 begin
  select @name = @p_taxid 
 end
 if @name is not null and @name not like '% near %'
 begin
  select @name =  '"' + REPLACE(@name,' ','" near "') + '"' 
  --> si solo viene un numero, no tiene espacios asi que solo le agrega las comillas, pero no hace el replace
 end

 if(@country_code='AR') /* SOLO ARGENTINA */
 begin
  SELECT distinct top(@max_rows) PADRONES.id_padron, identificacion,nombre_persona,iif(tipo_persona='F','FISICA','JURIDICA') AS tipo_persona,sexo
  ,c02_fecha_nac as fecha_nacimiento,fecha_defuncion,cuerpo_clave,prv_nombre as provincia,loc_nombre as localidad,identificadores.country_code,
        identificadores.identificador as identificador,padrones.ismodified ,padrones.apellidos,padrones.nombres--, '3' as tipo_consulta
  from dbo.padrones
   inner join identificadores on identificadores.identificador = padrones.identificador
   left join  domicilios_todos on domicilios_todos.cuit = padrones.identificacion and tipo_domicilio = 'F'  and visible = 1
   left join datos_personas on datos_personas.c01_cuit = padrones.identificacion
   WHERE CONTAINS((PADRONES.*),@name) and country_code in ('AR') and habilitado = 1
            RETURN

 end

    if(@country_code IS NULL) /*  EXCEPTO ARGENTINA */
 begin

  SELECT distinct top(@max_rows) PADRONES.id_padron, identificacion,nombre_persona,iif(tipo_persona='F','FISICA','JURIDICA') AS tipo_persona,sexo
  ,c02_fecha_nac as fecha_nacimiento,fecha_defuncion,cuerpo_clave,prv_nombre as provincia,loc_nombre as localidad,identificadores.country_code,
        identificadores.identificador as identificador,padrones.ismodified ,padrones.apellidos,padrones.nombres--, '4' as tipo_consulta
  from dbo.padrones
   inner join identificadores on identificadores.identificador = padrones.identificador
   left join  domicilios_todos on domicilios_todos.cuit = padrones.identificacion and tipo_domicilio = 'F'  and visible = 1
   left join datos_personas on datos_personas.c01_cuit = padrones.identificacion
   WHERE CONTAINS(PADRONES.*,@name) and country_code NOT in ('AR') and habilitado = 1
            RETURN

 end

END

GO

Used By

No items found