你可以使用这样的函数
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 @[email protected]+1
SELECT @checkSentence = SUBSTRING(@checkSentence, @pos+1, LEN(@checkSentence)[email protected])
END
return @count
END
并从包含在第一个
所以有行''我a''第二句得到单词的数量也应该被退回, 对? – dasblinkenlight
你可以检查两个空间的存在:'LIKE( '_%_ %%')'。 – xbonez
是为“我一个” ..或许检查前如果字含有较多的2个字符 –