I have a Table Valued Parameter (@KEYWORD) which just has one column with 0 to many rows of keywords that will query against one or two database (nvarchar) columns (REMARKS and SUPPLEMENTAL_REMARKS). Super simple concept.
What I am having trouble with is how to write the SQL to have it check for each of the individual keywords supplied against that one (or two) database columns.
Here's my unfinished part of the WHERE clause...
WHERE
(
CASE WHEN EXISTS (SELECT 1 FROM @KEYWORD) THEN
--check that some combination of either REMARKS or SUPPLEMENTAL_REMARKS contains all supplied values
CASE WHEN (
-- RES.REMARKS (or RES.SUPPLEMENTAL_REMARKS) LIKE %keyword[0]%
-- AND
-- RES.REMARKS (or RES.SUPPLEMENTAL_REMARKS) LIKE %keyword[1]%
-- AND
-- ... (this doesn't work for many reasons, but is just to give an idea)
) THEN
1
ELSE
0
END
ELSE --TVP (@KEYWORD) not supplied, so ignore this filter
1
END
) = 1