简体   繁体   中英

SQL Server 2016, How to use CONTAINS() with multiple word search of database?

New to SQL for the most part so perhaps there is a better approach but I'm looking for a way to search through a database using a textbox which can take any number of words/numbers. Basically like a search engine. Columns to be searched: [Col1], [Col2], and [Col3]

I have the table Full-Text indexed, is there a way I can use CONTAINS for this?

DECLARE @Search nvarchar(500)
SET @Search = 'foo 7 bar' -- can have multiple words/numbers

SELECT *
FROM TableName
WHERE CONTAINS([Col1] or [Col2] or [Col3], @Search)

I realize the last line syntax is incorrect but that's basically what I'm looking for. Shouldn't be exact match or case sensitive, nor should the order of wording matter ('red cat' = 'cat red') . Also would like to show results for close matches, ie, some of the keywords don't match anything.

Thank you!

Your each search word must be surrounded in quotes..

'"Hi" AND "I" AND "am" AND "Yogeesha"'

For more information, Have a look at https://msdn.microsoft.com/en-US/library/ms187787(v=SQL.90).aspx

事实证明,使用FREETEXT()得出我一直在寻找的结果。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM