[翻译]  SQL: Like vs Contains - Different Results

[CHINESE]  SQL:喜欢vs Contains - 不同的结果


I'm running two queries on a table.

我正在桌面上运行两个查询。

SELECT MSDS FROM dbo.MSDSSearch3 WHERE CONTAINS(MSDS, 'STYCAST')

And

SELECT MSDS FROM dbo.MSDSSearch3 WHERE MSDS like '%STYCAST%'

The first query will return

第一个查询将返回

'STYCAST 50300 LV'

And the second will return

而第二个将返回

'STYCAST 50300 LV'
'STYCAST 2851 BLACK'

Does anyone know why the like would return more values than the contains? Is there a problem with how I'm running contains? Thanks in advance.

有谁知道为什么喜欢会返回比包含更多的值?我正在运行的包含有问题吗?提前致谢。

2 个解决方案

#1


3  

Here's a similar post, where rebuilding the fulltext catalog seemed to solve the problem:

这是一篇类似的帖子,重建全文目录似乎解决了这个问题:

SQL Problem: Using CONTAINS() doesn't work, but LIKE works fine

SQL问题:使用CONTAINS()不起作用,但LIKE工作正常

#2


2  

CONTAINS is a totally different function, it is a predicate based query for full-text columns; it is not a function to determine if a column contain a string in it.

CONTAINS是一个完全不同的函数,它是一个基于谓词的全文列查询;它不是确定列是否包含字符串的函数。

For the query you are running, you could use this:

对于您正在运行的查询,您可以使用:

SELECT MSDS FROM dbo.MSDSSearch3 WHERE CONTAINS(MSDS, '"STYCAST*"')

There you have a prefix search, instead of a simple_term search like you currently have.

你有一个前缀搜索,而不是你现在拥有的simple_term搜索。

More details: http://msdn.microsoft.com/en-us/library/ms187787.aspx

更多细节:http://msdn.microsoft.com/en-us/library/ms187787.aspx


Maybe in the way you are using it the text 'STYCAST 2851 BLACK' don't fall into results because it have one more character than 'STYCAST 50300 LV', so it is a [7 of 17 match] vs a [7 of 16 match]. I'm not sure but that could explain this strange behavior.

也许在你使用它的方式中,文字'STYCAST 2851 BLACK'不会落入结果,因为它比'STYCAST 50300 LV'还要多一个字符,所以它是[17 of 7]和[7 of 16]比赛]。我不确定,但这可以解释这种奇怪的行为。


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号