SQL中的动态Like语句 [英] Dynamic Like Statement in SQL

查看:36
本文介绍了SQL中的动态Like语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我一直在绞尽脑汁思考如何做到这一点,我知道本网站上的某个天才会给出答案.基本上我正在尝试这样做:

I've been racking my brain on how to do this for a while, and i know that some genius on this site will have the answer. Basically i'm trying to do this:

SELECT column 
  FROM table 
 WHERE [table].[column] LIKE string1 
       OR [table].[column] LIKE string2 
       OR [table].[column] LIKE string3...

用于存储在表列中的搜索字符串列表.显然我不能手动为每个字符串做一个 like 语句,因为我希望表格是动态的.

for a list of search strings stored in a column of a table. Obviously I can't do a like statement for each string by hand because i want the table to be dynamic.

任何建议都会很棒.:D

Any suggestions would be great. :D

我正在使用 MSSQL :(

I'm using MSSQL :(

推荐答案

把参数(string1, string2, string3...)放入一个表(Params)然后JOIN 到表使用 LIKE JOIN 子句,例如

Put the parameters (string1, string2, string3...) into a table (Params) then JOIN to the table using LIKE the JOIN clause e.g.

SELECT column 
  FROM table AS T1
       INNER JOIN Params AS P1
          ON T1.column LIKE '%' + P1.param + '%';

这篇关于SQL中的动态Like语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆