我无法弄清楚为什么我的WHERE子句似乎仍然返回值是“ SPEC”的列值…我在这里做错了什么?[H1姓氏]是唯一包含此名称/值的列。
SELECT [H1 LAST Name] & ", " & [H1 FIRST Name] AS [FULL Name], [H1 E-Mail] AS [E-Mail], IIF([H1 Cell Phone] IS NULL, [Home Phone], [H1 Cell Phone]) AS Phone FROM NameLookup WHERE ((NameLookup.[H1 LAST Name] NOT LIKE '%SPEC%') OR (NameLookup.[H1 LAST Name] NOT LIKE '%MODEL%')) AND (NameLookup.[H1 LAST Name] IS NOT NULL) UNION ALL SELECT [H2 LAST Name] & ", " & [H2 FIRST Name] AS [FULL Name], [H2 E-Mail] AS [E-Mail], IIF([H2 Cell Phone] IS NULL, [Home Phone], [H2 Cell Phone]) AS Phone FROM NameLookup WHERE ((NameLookup.[H1 LAST Name] NOT LIKE '%SPEC%') OR (NameLookup.[H1 LAST Name] NOT LIKE '%MODEL%')) AND (NameLookup.[H2 LAST Name] IS NOT NULL) ORDER BY [FULL NAME]
LIKE根据查询运行的上下文,通配符会有所不同。
LIKE
在ADO中,通配符为%和_:
%
_
NameLookup.[H1 LAST Name] NOT LIKE '%SPEC%'
在DAO中,通配符为*和?:
*
?
NameLookup.[H1 LAST Name] NOT LIKE '*SPEC*'
或者,您可以使用ALIKE代替LIKE,然后db引擎将始终期望%和_通配符,而不管查询运行的上下文如何:
ALIKE
NameLookup.[H1 LAST Name] NOT ALIKE '%SPEC%'