Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to search for all keywords inclusive
Message
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
How to search for all keywords inclusive
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01357215
Message ID:
01357215
Vues:
62
Hi everybody,

I found yesterday a very interesting problem. Suppose, we have Keywords table and we need to search in our main table against these keywords to only include records which have all keywords in them. I was playing with it yesterday in VFP and I could not write a query in VFP to achieve it (I suspect we can do this with UDF, but I haven't figured this out).

For SQL Server I have this idea, which I haven't yet tried
declare @KeyWordsCount as int 
select @KeyWordsCount = count(*) from Keywords
with KeywordSearchCTE
as
(select * from myTable M INNER JOIN Keywords K on M.FieldToSearch like '%' + K.Search_Word + '%'
 UNION ALL
 select * from myTable M INNER JOIN Keywords K on M.FieldToSearch like '%' + K.Search_Word + '%' where K.Search_Word 
 NOT IN (select Search_Word from KeywordSearchCTE))

select M.FieldToSearch, count(*) as cnt_Occurs from myTable M 
inner join KeywordSearchCTE K on M.ID = K.ID group by 1 having cnt_Occurs = @KeyWordsCount
Do you think I'm going in the right direction?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform