【发布时间】:2010-09-06 10:13:33
【问题描述】:
如何从 sys.tables 中选择表名不包含特殊字词(传入参数)的表。
我想选择包含单词“customer”的所有表,但不选择以“old”结尾的表 名义上。
数据库中的表名
客户1
客户2
客户3
客户旧1
客户老2
需要的输出
客户1
客户2
客户3
【问题讨论】:
如何从 sys.tables 中选择表名不包含特殊字词(传入参数)的表。
我想选择包含单词“customer”的所有表,但不选择以“old”结尾的表 名义上。
数据库中的表名
客户1
客户2
客户3
客户旧1
客户老2
需要的输出
客户1
客户2
客户3
【问题讨论】:
SELECT * FROM sys.tables
WHERE TableName LIKE '%customer%'
AND TableName NOT LIKE '%old' -- note the lack of trailing '%'
【讨论】:
假设你有一个特殊词的参数,你可以这样做:
WHERE TableName LIKE @specialWord + '%'
AND TableName NOT LIKE '%' + @specialWord + '%old%'
【讨论】: