0
My goal is to create a select to return the total occurrences of a word, a column, per record
My table is modeled as follows: id / filename / qntd_pg / content
ex: I want to search how many times the word 'Rio' appears in the column [content], for each bank record.
The code below gives no error, but returns the amount as Null. It’s the first time I’m using the if structure in Sql Server.
Follows the Code:
declare @palavra varchar(30),
@cont int,
@result int
select
[DCM_conteudo]
FROM [dcm_digital].[dbo].[conteudo_dcm]
where upper([DCM_conteudo]) like '%Rio%' and [DCM_id] = 1
if @palavra = 'Rio'
begin
select @result = count(@cont);
end;
select @result;
Updating...
Solution in the post: SQL Server - Return only the searched word
Thank you for your help, but I’m still at an impasse. Your Cód. returns not only the searched words, but also words that have this word in their composition. Ex: the word is Rio, but also finds the word salary.
– Renata
Well observed! On the link https://stackoverflow.com/questions/6003240/cannot-use-a-contains-or-freetext-predicate-on-table-indexed-view-because-it. I believe we have achieved what you want. In this case you will need to use the Full-text index and use the CONTAINS or FREETEXT function as examples.
– rammonzito