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 '"*SORIA*" NEAR "*MARIA*" NEAR "*INES*"',null,'AR',30
exec api_padrones_2024 '"SORIA*" NEAR "MARIA*" NEAR "INES*"',null,'AR',30
exec api_padrones_2024 '27208925658',null,'AR',30
exec api_padrones_2024 '20892565',null,'AR',30
exec api_padrones_2024 '*59144',null,'AR',30
select * from padrones where contains(padrones.*, '"59144"')
select * from padrones where padrones.cuerpo_clave like '%59144'
*/
CREATE OR ALTER PROCEDURE dbo.api_padrones_15082024
@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
declare @palabras varchar(500) = null
declare @part varchar(500) = null
declare @full_search varchar(500) = null
declare @pos int = 0
declare @cant int = 0
--SET @name = '"' + @name + '"'
if @name is not null and @name not like '% near %'
select @name = '"' + REPLACE(@name,' ','" near "') + '"'
IF (@p_taxid is not null and ISNUMERIC(@p_taxid)=0 and @p_taxid not like '"%"' and @p_taxid not like '%" NEAR "%')
begin
set @palabras = ltrim(rtrim(@p_taxid))
if @palabras not like '% %' -- una sola palabra
begin
set @full_search = '"'+@palabras+'"'
end
else
begin
set @palabras = ltrim(rtrim(@palabras))+' '
set @pos = (select CHARINDEX(' ',@palabras))
while @pos != 0
begin
--EJEMPLO "MARIA*" NEAR "INES*" NEAR "SORIA*"
-- "*MARIA*" NEAR "*INES*" NEAR "*SORIA*"
select @part = SUBSTRING(@palabras,1,@pos-1)
if (@part != '' and @part != 'Y')
begin
set @cant = @cant + 1
if (len(@part) > 1)
set @part = '"*' + @part + '*"'
else
set @part = '"' + @part + '*"'
if @cant = 1
set @full_search = @part
else
set @full_search = @full_search + ' NEAR ' + @part
end
set @palabras = SUBSTRING(@palabras,@pos+1,500)
set @pos = (select CHARINDEX(' ',@palabras))
end
end
set @p_taxid = @full_search
select @p_taxid
end
IF (@p_taxid is not null and ISNUMERIC(@p_taxid)=1)
BEGIN
SET @p_taxid = '"'+@p_taxid+'"'
END
/*
select @full_search
return
*/
if(@p_taxid is not null and @country_code='AR') /* POR DNI O TAX ID SOLO ARGENTINA */
begin
/*if (len(@p_taxid)=11 and ISNUMERIC(@p_taxid)=1)
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--, '0' 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 identificacion = @p_taxid
and country_code in ('AR') and habilitado = 1 order by padrones.id_padron desc
end
else
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--, '1' 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.*, @p_taxid)
and country_code in ('AR') and habilitado = 1 order by padrones.id_padron desc
/*end*/
return
end
if(@p_taxid is not null and @country_code IS NULL) /* POR DNI O TAX ID 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--, '2' 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.*, @p_taxid) and habilitado = 1 and country_code NOT in ('AR')
return
end
if(@p_taxid IS NULL and @country_code='AR') /* POR NOMBRE O RAZÓNSOCIAL SOLO ARGENTINA */
begin
--SET @name = '"' + @name + '"'
if @name is not null and @name not like '% near %'
select @name = '"' + REPLACE(@name,' ','" near "') + '"'
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(@p_taxid IS NULL and @country_code IS NULL) /* POR NOMBRE O RAZÓNSOCIAL EXCEPTO ARGENTINA */
begin
--SET @name = '"' + @name + '"'
if @name is not null and @name not like '% near %'
select @name = '"' + REPLACE(@name,' ','" near "') + '"'
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
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 '"*SORIA*" NEAR "*MARIA*" NEAR "*INES*"',null,'AR',30
exec api_padrones_2024 '"SORIA*" NEAR "MARIA*" NEAR "INES*"',null,'AR',30
exec api_padrones_2024 '27208925658',null,'AR',30
exec api_padrones_2024 '20892565',null,'AR',30
exec api_padrones_2024 '*59144',null,'AR',30
select * from padrones where contains(padrones.*, '"59144"')
select * from padrones where padrones.cuerpo_clave like '%59144'
*/
CREATE OR ALTER PROCEDURE dbo.api_padrones_15082024
@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
declare @palabras varchar(500) = null
declare @part varchar(500) = null
declare @full_search varchar(500) = null
declare @pos int = 0
declare @cant int = 0
--SET @name = '"' + @name + '"'
if @name is not null and @name not like '% near %'
select @name = '"' + REPLACE(@name,' ','" near "') + '"'
IF (@p_taxid is not null and ISNUMERIC(@p_taxid)=0 and @p_taxid not like '"%"' and @p_taxid not like '%" NEAR "%')
begin
set @palabras = ltrim(rtrim(@p_taxid))
if @palabras not like '% %' -- una sola palabra
begin
set @full_search = '"'+@palabras+'"'
end
else
begin
set @palabras = ltrim(rtrim(@palabras))+' '
set @pos = (select CHARINDEX(' ',@palabras))
while @pos != 0
begin
--EJEMPLO "MARIA*" NEAR "INES*" NEAR "SORIA*"
-- "*MARIA*" NEAR "*INES*" NEAR "*SORIA*"
select @part = SUBSTRING(@palabras,1,@pos-1)
if (@part != '' and @part != 'Y')
begin
set @cant = @cant + 1
if (len(@part) > 1)
set @part = '"*' + @part + '*"'
else
set @part = '"' + @part + '*"'
if @cant = 1
set @full_search = @part
else
set @full_search = @full_search + ' NEAR ' + @part
end
set @palabras = SUBSTRING(@palabras,@pos+1,500)
set @pos = (select CHARINDEX(' ',@palabras))
end
end
set @p_taxid = @full_search
select @p_taxid
end
IF (@p_taxid is not null and ISNUMERIC(@p_taxid)=1)
BEGIN
SET @p_taxid = '"'+@p_taxid+'"'
END
/*
select @full_search
return
*/
if(@p_taxid is not null and @country_code='AR') /* POR DNI O TAX ID SOLO ARGENTINA */
begin
/*if (len(@p_taxid)=11 and ISNUMERIC(@p_taxid)=1)
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--, '0' 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 identificacion = @p_taxid
and country_code in ('AR') and habilitado = 1 order by padrones.id_padron desc
end
else
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--, '1' 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.*, @p_taxid)
and country_code in ('AR') and habilitado = 1 order by padrones.id_padron desc
/*end*/
return
end
if(@p_taxid is not null and @country_code IS NULL) /* POR DNI O TAX ID 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--, '2' 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.*, @p_taxid) and habilitado = 1 and country_code NOT in ('AR')
return
end
if(@p_taxid IS NULL and @country_code='AR') /* POR NOMBRE O RAZÓNSOCIAL SOLO ARGENTINA */
begin
--SET @name = '"' + @name + '"'
if @name is not null and @name not like '% near %'
select @name = '"' + REPLACE(@name,' ','" near "') + '"'
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(@p_taxid IS NULL and @country_code IS NULL) /* POR NOMBRE O RAZÓNSOCIAL EXCEPTO ARGENTINA */
begin
--SET @name = '"' + @name + '"'
if @name is not null and @name not like '% near %'
select @name = '"' + REPLACE(@name,' ','" near "') + '"'
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