2010-09-06 125 views
3

如何選擇從哪裏SYS.TABLES表名不containt特字(其中傳遞參數)表。SQL不喜歡聲明

我想選擇其中的包含誰與名「老」 結尾詞「顧客」,但不是那些所有表。

表名在DB

customer1表
的customer2
customer3
customerold1
customerold2

輸出求購

customer1表
的customer2
customer3

回答

11
SELECT * FROM sys.tables 
    WHERE TableName LIKE '%customer%' 
     AND TableName NOT LIKE '%old' -- note the lack of trailing '%' 

LIKE (Transact-SQL)

1

假設你有你的特殊字的參數,你可以這樣做:

WHERE TableName LIKE @specialWord + '%' 
AND TableName NOT LIKE '%' + @specialWord + '%old%'