数据量大全文检索
数据量小的话
--字符串分割存入临时表函数
CREATE FUNCTION [dbo].[SplitStr]
(
-- Add the parameters for the function here
@Str VARCHAR(8000), --将要处理的字符串
@SepStr VARCHAR(8000) --分隔符
)
RETURNS
@Tbl TABLE
(Item VARCHAR(8000)
)
AS
BEGIN
DECLARE @ItemString VARCHAR(8000)
DECLARE @itemIndex INT
SET @Str = @Str + @SepStr
WHILE(CHARINDEX(@SepStr, @Str) > 0 AND @Str <> @SepStr)
BEGIN
SET @itemIndex = CHARINDEX(@SepStr,@Str)
SET @ItemString = SUBSTRING(@Str, 1, @itemIndex - 1)
INSERT INTO @Tbl
SELECT @ItemString
SET @Str = SUBSTRING(@Str, @itemIndex + LEN(@SepStr), LEN(@Str) - @itemIndex)
END
RETURN
END
GO
declare @tblName varchar(50),@sql varchar(100)
declare cur CURSOR FORWARD_ONLY for
select name from SplitStr('C 精髓 教程',' ')
open cur
fetch next from cur into @item
while @@fetch_status=0
begin
select * from table1 where xx like '%'+@item+'%'
fetch next from cur into @item
end
close cur
deallocate cur
GO