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, i.e., some of the keywords don't match anything.
Thank you!