i want to create a stored procedure that pulls a list from a table.
currently I am searching a comments field for keywords, using a like statement for each keyword, but I would like to pull the list of keywords from another table so if the keywords change i dont have to change the query. Is this possible?
example of what i am currently doing.
select * from tblCustomerInfo
where comments like '%Test%' or comments like '%One%' or comments like '%Two%'
Microsoft SQL ServerMicrosoft SQL Server 2008SQL
Last Comment
Scott Pletcher
8/22/2022 - Mon
Scott Pletcher
Sure. Load "Test", "One", etc. into a table and then you can do this:
SELECT *
FROM tblCustomerInfo ci
WHERE
EXISTS(SELECT 1 FROM otherTable o WHERE ci.comments LIKE o.string)
dkilby
ASKER
it doesnt work, i put the keywords in a separate table and get nothing back, i test by doing this, and returned rows.
SELECT *
FROM tblCustomerInfo ci
WHERE
EXISTS(SELECT 1 FROM KeyWords o WHERE ci.comments LIKE '%One%')
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
SELECT *
FROM tblCustomerInfo ci
WHERE
EXISTS(SELECT 1 FROM otherTable o WHERE ci.comments LIKE o.string)