I’m trying to create the following SQL query (as in, this is an example of the final query) :-
DECLARE @SearchQuery AS NVARCHAR(100) = 'yellow bird'
SELECT Id, Name
FROM dbo.FooBars
WHERE CONTAINS(Name, N'FORMSOF(Thesaurus, yellow)')
AND CONTAINS(Name, N'FORMSOF(Thesaurus, bird)')
Notice how I’ve got two CONTAINS lines? This is because the search query has two words in it. (a space is the delimiter). This query could be from 1 to n words.
How can I generate this SQL code based upon the number of words in the search query?
You can put the “AND” in the contains itself, so it coud be
with the string ‘FORMSOF(Thesaurus, yellow) AND FORMSOF(Thesaurus, bird)’
built up into a variable like