Database: Sql Server
I have table column named page_text which contains following value
\" I Love stackoverflow.com because i can post questio
declare @search varchar(10) = 'I'
select len(replace(PageText, @search, @search + '#'))
- len(PageText) as Count from YourTable
SELECT (LEN(@Text) - LEN(REPLACE(@Text,@SearchString,''))/(Len(@SearchString))
based on this code: http://www.sql-server-helper.com/functions/count-character.aspx
you create a function:
CREATE FUNCTION [dbo].[ufn_CountSpecificWords] ( @pInput VARCHAR(1000), @pWord VARCHAR(1000) )
RETURNS INT
BEGIN
RETURN (LEN(@pInput) - LEN(REPLACE(@pInput, ' ' + @pWord + ' ', '')))
END
GO
this however implies that you save your strings with a leading and trailing space and you replace any other separators like ',' and '.' with spaces.
and you need to refrase your question if you want the count of words or just the appeareance of a word.