In our case, we’re restricted to SQL Server 2000.
Say we have a table “Articles” with a field “ArticleText”. How do we search a string consisted of many words, and return the number of found occurrences.
An example of a search string: John is a nice boy (so it contains 5 words)
ID ArticleText Result
1 John is going to learn 2
2 John is doing his homework nice-ly 3
3 John is a nice boy 5
Up to now I’ve found a split function
for sql server 2000 to delimit the search string. Now I’m trying to iterate through the records and display the count of found words in one field, but I got stuck. Any help?
SQL Server 2000 solution
New idea. Try splitting the search string first into 1 temp table. Then joining back to the articles using wild cards.
I tested this on SQL Server 2008 R2 with 2000 compatibility mode.
The 2 join conditions ensure that it matches the first word or any beginning of words (to get ‘nice-‘ ).
You should tweak this to your requirements and consider replace functions for the hyphen and other punctuation.