MS SQL CONTAINSTABLE() - Must Contain Both Words

This does not return any results even though both "red" and "yellow" are found because the exact phrase "red and yellow" is not found:


Open in new window

How can I use CONTAINSTABLE so that both the words "red" and "yellow" are found in any order or position?
LVL 10
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott PletcherSenior DBACommented:

'FORMSOF(THESAURUS, "red" AND "yellow")')

I believe because of the double quotes surrounding the whole text, SQL "thinks" you are looking for the string 'red AND yellow', rather than 'red' and 'yellow'.
skijAuthor Commented:
@Scott Pletcher: your idea returns a syntax error.

I need a solution that actually works.
Scott PletcherSenior DBACommented:
Did you complete the JOIN syntax??  You left the JOIN "hanging" -- no table alias for the CONTAINSTABLE and no ON clause for the JOIN -- on your initial post so I didn't know how to complete it, but it cause a syntax error if left hanging.
skijAuthor Commented:
I  figured it out, based on your comment.  Each term needs its own FORMSOF() statement.

This works:

INNER JOIN CONTAINSTABLE(ipm_asset, Search_Tags_Speedy, 'FORMSOF(INFLECTIONAL, "foods") AND FORMSOF(INFLECTIONAL, "view") AND FORMSOF(INFLECTIONAL, "whole")') as ipmrank  ON a.asset_id = ipmrank.[KEY]


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skijAuthor Commented:
Each term needs its own FORMSOF() statement.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.