如何在sql中搜索全文搜索中的双引号

时间:2014-04-09 21:39:14

标签: sql sql-server-2012 full-text-search containstable

我的关键字中有双引号。如何在我的全文搜索查询中搜索此内容。 我有这个查询

SELECT  top 10 K.[KEY], 10, K.[RANK]
FROM    CONTAINSTABLE(ProductKeywords, Keywords, '("19*") AND ( "<Cat>5" OR "<Cat>30" OR "<Cat>398" ) AND NOT "<Blocked>"' ) AS k

它工作正常但我的关键字中有双引号,如

SELECT  top 10 K.[KEY], 10, K.[RANK]
FROM    CONTAINSTABLE(ProductKeywords, Keywords, '("19"*") AND ( "<Cat>5" OR "<Cat>30" OR "<Cat>398" ) AND NOT "<Blocked>"' ) AS k

它给出了这个错误

Msg 7630, Level 15, State 3, Line 1
Syntax error near '*' in the full-text search condition '("19"*") AND ( "<Cat>5" OR "<Cat>30" OR "<Cat>398" ) AND NOT "<Blocked>"'.

2 个答案:

答案 0 :(得分:1)

要转义双引号,只需将它们加倍,例如

SELECT * FROM Tbl WHERE Contains(name, '""quoted""')

答案 1 :(得分:0)

How do you escape double quotes inside a SQL fulltext 'contains' function?

SELECT TOP 10
    K.[KEY]
  , 10
  , K.[RANK]
FROM
    CONTAINSTABLE(ProductKeywords, Keywords, '("19*") AND ( "<Cat>5" OR "<Cat>30" OR "<Cat>398" ) AND NOT "<Blocked>"')
    AND Keywords LIKE '19"%'
    AS k