A union of curiosity and data science

Knowledgebase and brain dump of a database engineer


T-SQL Word Count Function

 

 
 
Function

create function f_count_word_in_string (@field varchar(max), @word varchar(max))

returns int
as
begin

   return (LEN(@field) - LEN(REPLACE(@field, @word,'')))/LEN(@word)
end
 
 
 

 Test:

select dbo.f_count_word_in_string('tester

I want to test this, but how?  

oh tester tester', 'tester')

 
 Result:
 
 
 

Comments (1) -

  • Add Hunters

    4/23/2020 3:06:35 PM | Reply

    Grate article. New to Addhunters? It's incredibly easy to become a member of our community, and FREE to list your classified ads to interact with all members. Every day, hundreds of listings get listed for free by our Addhunters members. You can always upgrade your membership and get ahead of the crowd. With Addhunters you're going to benefit from our international usages!Items listed on Add Hunters include electronics, pets, cars and, vehicles and other categories including land and property. The categories with the highest volume on the site are vehicles and property. For more details please visit our web site http://www.addhunters.com <a href="http://www.addhunters.com";>property finder doha</a>

Add comment