你如何在sql中简单地在一个列中多次使用不表达式?

时间:2013-06-03 15:55:25

标签: sql sql-server sql-server-2008-r2

select  (Col_Name) 
where (Col_Name) not like '%abc%'
and (Col_Name) not like '%cap%'
and (Col_Name) not like '%tis%'
and (Col_Name) not like '%sat%'
and (col_Name) not like '%plk%'

1 个答案:

答案 0 :(得分:3)

SQL Server本身不支持正则表达式,但您可以安装CLR函数来使用它们。

实现这一目标的一种方法是

SELECT *
FROM   YourTable
WHERE  col_Name IS NOT NULL AND
           NOT EXISTS (SELECT *
                       FROM   (VALUES ('abc'),
                                      ('cap'),
                                      ('tis'),
                                      ('sat'),
                                      ('plk')) V(C)
                       WHERE  col_Name LIKE '%' + C + '%') 

虽然我认为这不是一种改进。