sql中的全文搜索条件

时间:2017-07-06 09:41:02

标签: sql-server sql-server-2008

 select * from quotestable where contains(RelatedKeyword, 'Benjamin Franklin Quotes')

返回错误

 Msg 7630, Level 15, State 3, Line 1
 Syntax error near 'Franklin' in the full-text search condition 'Benjamin Franklin'.

我很惊讶为什么。理想情况下,它应该搜索该单词,但它已返回错误消息。

3 个答案:

答案 0 :(得分:1)

尝试使用像这样的

select * from quotestable where RelatedKeyword like '%Benjamin Franklin Quotes%' 

答案 1 :(得分:1)

我相信您正在Benjamin Franklin Quotes

中搜索完整的字符串RelatedKeyword

你需要使用双引号来逃避单词之间的空格。

select * 
from quotestable 
where contains(RelatedKeyword, '"Benjamin Franklin Quotes"')

答案 2 :(得分:1)

使用CONTAINSCONTAINSTABLE匹配单词和短语。

  

它在full-text indexed上执行SQL Server全文搜索   包含基于字符的数据类型的列。Text Search

select * from quotestable where CONTAINSTABLE(<tablename>, <ColumnName> ,'Benjamin Franklin Quotes')

CONTAINS

select * from quotestable where CONTAINS(<ColumnName> ,'"Benjamin Franklin Quotes"')

是一串没有空格或标点符号的字符。

短语

每个单词之间是否有一个或多个单词。

  

短语应用双引号括起来(&#34;&#34;)。