Welcome to Julian Kuiters Saturday, August 18 2018 @ 05:11 PM AEST

Count the Occurrence of a Phrase or Word in a Column

  • Contributed by:
SQL Server 2000

Simple little bit of code that will show you the number of times the value of @PhraseOrWordToCount is found in TextColumn.

SELECT (LEN(TextColumn) - LEN(REPLACE(TextColumn, @PhraseOrWordToCount, '')) / LEN(@PhraseOrWordToCount)) AS Occurrence
FROM dbo.MyTable

I noticed this on Simon Sabin's blog, I think it has more applications than just FullText searches so I thought I'd do a modified re-post.