Reputation: 27
I am trying to create a SQL trigger that will alert me when a user types in certain words. I have it working with a single word but I need to get this working with a list of words. How can I get something similar to the following, that will search a list of words stored in some other location.
WHERE CHARINDEX('BadWord',Body) > 0
Upvotes: 1
Views: 2266
Reputation: 432180
Join onto a bad word table
select
*
from
INSERTED I
JOIN
myBadWords B ON I.Body LIKE '%' + b.badword + '%'
This won't run well though because of the leading %. Full Text Search would be better
Upvotes: 0
Reputation: 56769
Join with a BadWords table and compare to the entries in that list in your trigger:
select
*
from
inserted i, badwords b
where
charindex(b.badword, i.Body) > 0
Upvotes: 1