如何在SQL全文“包含”函数中避免双引号? [英] How do you escape double quotes inside a SQL fulltext 'contains' function?

查看:201
本文介绍了如何在SQL全文“包含”函数中避免双引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在MS SQL'包含'函数中转义双引号字符?

  SELECT决定
FROM table
WHERE CONTAINS(decision,'34AND wide')

通常包含)期望双引号围绕一个确切的短语来匹配,但是我想搜索一个实际的双引号字符,我尝试使用\,`,甚至另一个双引号来转义它,但没有一个有效。 / p>

PS我意识到这样一个简单的例子也可以使用LIKE语句完成,但是我需要使用全文搜索功能,这里提供的查询已经从

解决方案

文档


标点符号被忽略,因此, CONTAINS(测试,计算呃故障)匹配一行与值,我的电脑在哪里?没有找到它将是昂贵的。


由于 FULLTEXT 甚至没有标点符号索引,您需要使用 LIKE 精细筛选结果:

  SELECT决定
FROM表
WHERE CONTAINS(决定,'34 AND wide')
和决定LIKE'%34%'

这将保留全文的好处。


How do you escape a double quote character inside a MS SQL 'contains' function?

SELECT decision
FROM table 
WHERE CONTAINS(decision, '34" AND wide')

Normally contains() expects double quotes to surround an exact phrase to match, but I want to search for an actual double quote character. I've tried escaping it with \, `, and even another double quote, but none of that has worked.

P.S. I realize a simple example like this could also be done using the LIKE statement, but I need to use the fulltext search function. The query I provided here has been simplified from my actual query for example purposes.

解决方案

From documentation:

Punctuation is ignored. Therefore, CONTAINS(testing, "computer failure") matches a row with the value, "Where is my computer? Failure to find it would be expensive."

Since FULLTEXT does not even index the punctuation, you'll need to fine-filter your results using LIKE:

SELECT  decision
FROM    table 
WHERE   CONTAINS(decision, '34 AND wide')
        AND decision LIKE '%34"%'

This will preserve the benefits of fulltext.

这篇关于如何在SQL全文“包含”函数中避免双引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆