【问题标题】:Check any of the columns contains character from a string检查任何列是否包含字符串中的字符
【发布时间】:2012-11-15 21:39:50
【问题描述】:

我有一个表中的列,其中包含这样的值

class1   class2   class3   class4
A        D        0        0
0        A        B        0
B        0        0        C
A        0        D        0

我有像First="A,B"Second="C,D"这样的字符串

如何检查这四列中任何一列中包含的字符串中的任何一个字符

【问题讨论】:

    标签: sql-server in-clause


    【解决方案1】:
    select * from t 
    where 
    
    'A,B' like '%'+class1+'%'
    or
    'A,B' like '%'+class2+'%'
    or
    'A,B' like '%'+class3+'%'
    or
    'A,B' like '%'+class4+'%'
    

    【讨论】:

      【解决方案2】:
      select * from yourtable where class1 in('A,B,C,D')
      UNION
      select * from yourtable where class2 in('A,B,C,D')
      UNION
      select * from yourtable where class3 in('A,B,C,D')
      UNION
      select * from yourtable where class4 in('A,B,C,D')
      

      【讨论】:

      • 感谢您的回复,但需要时间
      猜你喜欢
      • 1970-01-01
      • 2015-03-24
      • 1970-01-01
      • 1970-01-01
      • 2015-09-08
      • 2014-08-09
      • 2013-12-04
      • 2021-06-12
      相关资源
      最近更新 更多