You can use such a function
CREATE FUNCTION [dbo].[CheckSentece] (@mainSentence varchar(128), @checkSentence varchar(128)) RETURNS NUMERIC AS BEGIN SET @mainSentence=LOWER(@mainSentence) SET @checkSentence=LOWER(@checkSentence) DECLARE @pos INT DECLARE @word varchar(32) DECLARE @count NUMERIC SET @count=0 WHILE CHARINDEX(' ', @checkSentence) > 0 BEGIN SELECT @pos = CHARINDEX(' ', @checkSentence) SELECT @word = SUBSTRING(@checkSentence, 1, @pos-1) DECLARE @LEN NUMERIC //Simple containment check, better to use another charindex loop to check each word from @mainSentence SET @LEN=(SELECT LEN(REPLACE(@mainSentence,@word,''))) if (@LEN<LEN(@mainSentence)) SET @ count=@count +1 SELECT @checkSentence = SUBSTRING(@checkSentence, @pos+1, LEN(@checkSentence) -@pos ) END return @count END
and get the number of words from the second sentence contained in the first
source share