多个不喜欢的陈述

时间:2016-10-05 15:59:22

标签: sql sql-like

是否有更简单(更清洁)的方法来完成以下任务:

AND Prov_Credentialing not like ('%AS%') AND Prov_Credentialing not like ('%CI%')
AND Prov_Credentialing not like ('%DI%') AND Prov_Credentialing not like ('%FQ%')
AND Prov_Credentialing not like ('%EM%') AND Prov_Credentialing not like ('%HS%')
AND Prov_Credentialing not like ('%SN%') AND Prov_Credentialing not like ('%PH%')
AND Prov_Credentialing not like ('%AN%') AND Prov_Credentialing not like ('%RQ%')

Prov_Credentialing列可以包含具有多个代码的记录。例如,列数包含“AS,ED”。因此,NOT IN语句不起作用,因为我需要包含任何包含“AS”的代码。

我需要在NOT LIKE语句中排除更多代码,我刚才列出了前10个。

谢谢, 格雷格

1 个答案:

答案 0 :(得分:2)

将模式存储在单独的表中:

CREATE TABLE NOT_LIKES (pattern VARCHAR(4));

INSERT INTO NOT_LIKES VALUES ('%AS%');
...

SELECT ...
WHERE  ...
AND    NOT EXISTS (SELECT * FROM NOT_LIKES WHERE Prov_Credentialing LIKE pattern)