我有一个带有描述字段(varchar(max))的表(表 A)。我有另一个带有关键字字段的表(表 B)。
对于表 BI 中的所有行,希望返回表 A 中包含表 A 中指定的关键字至少出现一次的所有行。
我在这个网站上用谷歌搜索过,但没有找到任何如何做到这一点的例子。我发现的所有示例都要求您输入搜索字符串,而不仅仅是动态运行查询。
您可以使用通配符和这样的连接:
declare @TableA table (description varchar(max))
declare @TableB table (keyword varchar(max))
insert into @TableA values ('The quick brown fox jumped over the lazy dog.'), ('I think, therefore I am.')
insert into @TableB values ('jumped'), ('therefore'), ('fox'), ('th')
select * from @TableB b
inner join @TableA a on a.description like '%' + b.keyword + '%'
结果:
keyword description
jumped The quick brown fox jumped over the lazy dog.
therefore I think, therefore I am.
fox The quick brown fox jumped over the lazy dog.
th The quick brown fox jumped over the lazy dog.
th I think, therefore I am.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句