How can I parameterize the following query? (By the way I'm using a full text indexed table, hence the CONTAINS()
)
SELECT * FROM Table WHERE CONTAINS(Column, 'cat OR dog')
and ((column NOT LIKE '%[^ cat OR dog]%'));
This didn't work:
DECLARE @term1 VARCHAR(10);
DECLARE @term2 VARCHAR(10);
SET @term1 = 'cat';
SET @term2 = 'dog';
SET @term3 = @term1 + ' ' + 'OR' + ' ' + @term2;
SET @term4 = '[^ @term1 OR @term2 ]' ;
SELECT * FROM table WHERE CONTAINS(column, @term3) <--up to this point works
AND (column NOT LIKE '%[@term4]%'); <--this part doesn't include the second term (@term2)
If you'd like to fiddle with this on your end, my Full Text Indexed table looks like:
animalListID AnimalsList
1 cat dog
2 cat
3 cat dog bird
(basically i need the parameterized version of the SELECT
statement which returns the rows with 'cat dog' and 'cat' and NOT 'cat dog bird')
**This is a VERY oversimplified version of my data, but the question is an exact match of the concept I'm trying to achieve. The table will have millions of rows, and many terms in each row.