Hi. Suppose, I have for example this string field in my sql database "never say never" and I want to count how many times "never" appear in the string in sql server 2008, so how I can check that.
Here is the working example
Declare @string VARCHAR(MAX) ='Never say Never' DECLARE @tosearch VARCHAR(MAX)='Never' SELECT (DATALENGTH(@string)-DATALENGTH(REPLACE(@string,@tosearch,'')))/DATALENGTH(@tosearch) AS OccurrenceCount
Above is the sample output.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly