"SQL Question: How can I store multiple wildcard strings in a table and pass them on to the LIKE operator in a where clause"

"SQL Question: How can I store multiple wildcard strings in a table and pass them on to the LIKE operator in a where clause"

这是我的场景: 我有一个 table 说:dbo.Filters(FilterName vacrchar(100),Category varchar(100)) 样本值如下

我使用这个 table 来存储示例字符串,这些示例字符串应该在 where 原因中使用 like 运算符与通配符搜索一起使用,并且其中有几个要在不同的条件/case 语句中使用基于它们所在的类别,所以我不能简单地使用 where 和 and/or 条件,而是必须将它们存储在 table 中,并且这些字符串经常变化。所以,对我来说唯一的方法是对它们进行分类并将类别用作我的过滤条件的一部分并将相应的值传递到 where 子句中。它必须用于类似下面的内容,但来自 table 而不是仅在查询中提及它们:

select *
from dbo.AnotherTable 
where [freeformtextfield] like ('%I have reached%','%I've reached%','%I reached%') 

-- 我的已达到/未达到类别过滤器

连接表:

select distinct a.* 
from dbo.AnotherTable a inner join dbo.Filters f
on a.[freeformtextfield] like concat('%', f.[FilterName], '%')

你也可以使用 EXISTS

select  *
from    dbo.AnotherTable
where   exists (select  1 from  Filters where   [freeformtextfield] like '%' + FilterName + '%')