如何在 SQL 服务器中将 LIKE 转换为 CONTAINS?
How to convert LIKE to CONTAINS in SQL Server?
这是一个使用'LIKE'的查询:
SELECT JoinedColumnInfo FROM [dbo].[ImportedData]
WHERE CategoryId = 11131700
AND JoinedColumnInfo LIKE '%usb%'
'LIKE'结果table是:
1.F5TYEU 2815124 KOSS cs100usb Double Sided Comm Headset USB, Noise Cancelling Microphone Wired
2.PODCASTUDIOUSB BEHRINGER Studio PodCast Kit - Includes Microphone, Mixer and Headphones
3.NUYVSRB 79X3419cs100usb KOSS Double Sided Comm Headset USB, Noise Cancelling Microphone
这与使用 'CONTAINS' 的查询相同:
SELECT JoinedColumnInfo FROM [dbo].[ImportedData]
WHERE CategoryId = 11131700
AND CONTAINS (JoinedColumnInfo, '"usb*"')
CONTAINS 结果 table 是:(2 个结果)
1.F5TYEU 2815124 KOSS cs100usb Double Sided Comm Headset USB, Noise Cancelling Microphone Wired
3.NUYVSRB 79X3419cs100usb KOSS Double Sided Comm Headset USB, Noise Cancelling Microphone
在 CONTAINS 查询中 我没有得到记录 编号 2 为什么?
如何从 'LIKE' 转换为 'CONTIANS' 并获得相同的结果?
LIKE 和 CONTAINS 的工作方式存在一些根本差异,最重要的是在使用 CONTAINS 时,您需要在列上有一个现有的 full-text 索引。
来自here:
CONTAINS can search for:
- A word or phrase.
- The prefix of a word or phrase.
- A word near another word.
- A word inflectionally generated from another (for example, the word drive is the inflectional stem of drives, drove, driving, and driven).
- A word that is a synonym of another word using a thesaurus (for example, the word "metal" can have synonyms such as "aluminum" and
"steel").
另一方面,LIKE 使用模式匹配来查找简单的字符串匹配来查找您要查找的值。
这是一个使用'LIKE'的查询:
SELECT JoinedColumnInfo FROM [dbo].[ImportedData]
WHERE CategoryId = 11131700
AND JoinedColumnInfo LIKE '%usb%'
'LIKE'结果table是:
1.F5TYEU 2815124 KOSS cs100usb Double Sided Comm Headset USB, Noise Cancelling Microphone Wired
2.PODCASTUDIOUSB BEHRINGER Studio PodCast Kit - Includes Microphone, Mixer and Headphones
3.NUYVSRB 79X3419cs100usb KOSS Double Sided Comm Headset USB, Noise Cancelling Microphone
这与使用 'CONTAINS' 的查询相同:
SELECT JoinedColumnInfo FROM [dbo].[ImportedData]
WHERE CategoryId = 11131700
AND CONTAINS (JoinedColumnInfo, '"usb*"')
CONTAINS 结果 table 是:(2 个结果)
1.F5TYEU 2815124 KOSS cs100usb Double Sided Comm Headset USB, Noise Cancelling Microphone Wired
3.NUYVSRB 79X3419cs100usb KOSS Double Sided Comm Headset USB, Noise Cancelling Microphone
在 CONTAINS 查询中 我没有得到记录 编号 2 为什么? 如何从 'LIKE' 转换为 'CONTIANS' 并获得相同的结果?
LIKE 和 CONTAINS 的工作方式存在一些根本差异,最重要的是在使用 CONTAINS 时,您需要在列上有一个现有的 full-text 索引。
来自here:
CONTAINS can search for:
- A word or phrase.
- The prefix of a word or phrase.
- A word near another word.
- A word inflectionally generated from another (for example, the word drive is the inflectional stem of drives, drove, driving, and driven).
- A word that is a synonym of another word using a thesaurus (for example, the word "metal" can have synonyms such as "aluminum" and "steel").
另一方面,LIKE 使用模式匹配来查找简单的字符串匹配来查找您要查找的值。