1
I have a problem where the Cód. below returns not only the searched words, but tb words that have this word in their composition.
Ex: The term is Rio, but also finds terms as salary.
In the link below, you can see my first question on the subject. SQL Server - calculate number of word occurrences in a column, per record
DECLARE @conteudo_dcm TABLE (DCM_id INT IDENTITY(1,1), DCM_conteudo VARCHAR(100))
INSERT INTO @conteudo_dcm VALUES ('Rio e a RIO vai se repetir então teremos 2 :D')
INSERT INTO @conteudo_dcm VALUES ('um Rio apenas... então teremos 1 salario :D')
INSERT INTO @conteudo_dcm VALUES ('tres pra este caso. Rio, Rio, Rio XD.. então 3.. blz?')
declare @palavra varchar(30) = 'Rio',
@cont int,
@result int,
@palavraLike varchar(30) = '%Rio%'
SELECT
[DCM_conteudo],
(LEN([DCM_conteudo]) - LEN(REPLACE([DCM_conteudo], @palavra, ''))) /
LEN(@palavra)
FROM @conteudo_dcm
where upper([DCM_conteudo]) like @palavraLike-- and [DCM_id] = 1
It seems to me that what you need is: 1) if it is the beginning of the field then 'river'; 2) if it is the end of the field then ' river' and if it is in the middle of the field then 'river'. It may be that the ' character is replaced by some punctuation character. I don’t know if in SQL-Server it is possible to use regular expressions that would certainly make your life easier.
– anonimo