你可以使用這樣的函數
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個字符 –