sql server全文搜索多值包含

时间:2011-11-09 17:42:43

标签: sql-server full-text-search

我使用全文搜索来查找在另一个单词附近有单词的行,例如:

select *
from mytable where
contains (mycolumn, 'someword1 near someword2')

从现在开始,我的输入将是一个表格,如:

declare @words table  
( 
    word varchar(100) not null 
) 

insert into @words (word) values ('someword1') 
insert into @words (word) values ('someword2') 
insert into @words (word) values ('someword3') 

是否可以重写查询以获得相同的结果,或者我需要在单行文本中转换@words行?

1 个答案:

答案 0 :(得分:1)

这个怎么样:

declare @words table (word varchar(100) not null) 
insert into @words (word) values ('someword1') 
insert into @words (word) values ('someword2') 
insert into @words (word) values ('someword3') 

declare @q varchar(4000)
set @q = ''
select @q = @q + ' ~ ' + word from @words  -- join all words
set @q = substring(@q, 4, 4000)            -- remove the first ' ~ '

select *
  from mytable
 where contains (mycolumn, @q)