dbo.obtener_edictos_mencionado_2

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

1
Name Data Type Length Description
@palabras varchar 8000

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

/* 
EXEC obtener_edictos_mencionado '"17726090" near "burgol"'
EXEC obtener_edictos_mencionado '"17726090"'

EXEC obtener_edictos_mencionado '"17726090" or (NEAR((REVILLA ,CORNEJO, SERGIO),0,true)  OR NEAR((REVILLA,SERGIO,CORNEJO),0,true) OR NEAR((SERGIO,REVILLA,CORNEJO),0,true) OR NEAR((SERGIO,CORNEJO,REVILLA),0,true) OR NEAR((REVILLA,CORNEJO,SERGIO),0,true) OR NEAR((REVILLA,SERGIO,CORNEJO),0,true))'

EXEC obtener_edictos_mencionado 'NEAR((REVILLA ,CORNEJO, SERGIO),0,true)  OR NEAR((REVILLA,SERGIO,CORNEJO),0,true) OR NEAR((SERGIO,REVILLA,CORNEJO),0,true) OR NEAR((SERGIO,CORNEJO,REVILLA),0,true) OR NEAR((REVILLA,CORNEJO,SERGIO),0,true) OR NEAR((REVILLA,SERGIO,CORNEJO),0,true)'
EXEC obtener_edictos_mencionado 'NEAR((MALDONADO,MIRIAM,NELIDA),0,true) OR NEAR((MALDONADO,NELIDA,MIRIAM),0,true) OR NEAR((MIRIAM,MALDONADO,NELIDA),0,true) OR NEAR((MIRIAM,NELIDA,MALDONADO),0,true) OR NEAR((NELIDA,MALDONADO,MIRIAM),0,true) OR NEAR((NELIDA,MIRIAM,MALDONADO),0,true)'



select top /*500*/
 500 id_fide, id_boletin, 
provincia_boletin = IIF(provincias.prv_nombre is null, iif(sociedades_constituciones.provincia_sociedad is null,sociedades_constituciones.fuente,sociedades_constituciones.provincia_sociedad), provincias.prv_nombre),    
fecha_publicacion, 
convert(varchar(11),fecha_publicacion,103) as fecha_publicacion_DMY,
cast(contenido_archivo as varchar(max)) AS contenido_archivo,razon_social,
documento_soc

from sociedades_constituciones  
left join provincias on provincias.prv_codigo = sociedades_constituciones.provincia_boletin and pai_codigo_ifx = 54

where contains(contenido_archivo,'"17726090" or (NEAR((REVILLA ,CORNEJO, SERGIO),0,true)  OR NEAR((REVILLA,SERGIO,CORNEJO),0,true) OR NEAR((SERGIO,REVILLA,CORNEJO),0,true) OR NEAR((SERGIO,CORNEJO,REVILLA),0,true) OR NEAR((REVILLA,CORNEJO,SERGIO),0,true) OR NEAR((REVILLA,SERGIO,CORNEJO),0,true))')


order by fecha_publicacion desc




*/

CREATE OR ALTER PROCEDURE dbo.obtener_edictos_mencionado_2  

@palabras varchar(8000) 

AS
BEGIN

SET NOCOUNT ON


declare @respuesta table 
(
id_fide bigint, 
id_boletin bigint, 
provincia_boletin varchar(max),
fecha_publicacion date,
fecha_publicacion_DMY varchar(10),
contenido_archivo varchar(max),
razon_social  varchar(500),
cuit_soc varchar(20), 
Id INT IDENTITY(1,1))


insert into @respuesta 
(
id_fide,
id_boletin,
provincia_boletin,
fecha_publicacion,
fecha_publicacion_DMY,
contenido_archivo,
razon_social,
cuit_soc)

select top /*500*/ 50 id_fide, id_boletin, 
provincia_boletin = IIF(provincias.prv_nombre is null, iif(sociedades_constituciones.provincia_sociedad is null,sociedades_constituciones.fuente,sociedades_constituciones.provincia_sociedad), provincias.prv_nombre),    
fecha_publicacion, 
convert(varchar(11),fecha_publicacion,103) as fecha_publicacion_DMY,
cast(contenido_archivo as varchar(max)) AS contenido_archivo,razon_social,
documento_soc

from sociedades_constituciones  
left join provincias on provincias.prv_codigo = sociedades_constituciones.provincia_boletin and pai_codigo_ifx = 54

where (contains(contenido_archivo,@palabras))

order by fecha_publicacion desc


-- 15/01/2024: Devolvemos lo que guardamos en la tabla @respuesta, pero descartando los que son de la misma fecha y principio del texto igual, 
--             (porque seguramente los que tienen la misma fecha son duplicados aunque el texto no este exactamente igual).
select * from @respuesta a
where not exists (select * from @respuesta b where b.fecha_publicacion = a.fecha_publicacion 
              and convert(varchar(100),dbo.fn_StripCharacters(upper(convert(varchar(200),b.contenido_archivo)), '^A-Z0-9/')) = 
               convert(varchar(100),dbo.fn_StripCharacters(upper(convert(varchar(200),a.contenido_archivo)), '^A-Z0-9/'))            
               and b.id > a.id) 
order by a.fecha_publicacion desc


END

GO

Used By

No items found