Not Like Operator 不使用 ACCESS/SQL 查询

问题描述

我目前正在尝试排除带有“Not Issue”字样的评论,但由于某种原因它部分起作用。当我删除下面的代码时,我得到 100 个值,但是当我添加下面的语法时它返回 50,但是在这 50 个字段中,仍有一些行包含“Not Issue”。

INSERT INTO Combined_Comments ( [ID],[Comment] ) 
SELECT [Comments_001].[ID],IIf([Comments]<>" ","BR
#" & [Branch Number] & " - " & [Comments],[Comments]) AS [Dup Comment] 
FROM [Comments_001] 
WHERE ((Not (IIf([Comments]<>" ","BR #" & [Branch Number] & " - " & [Comments],[Comments]))<>"%not issue%") AND (([Dup Vin Comments_085].[Dup Ind])<>" "));

解决方法

在 MS Access 中,类似的通配符是“*”,而在 SQL Server 中它是“%”,因此您的查询中的 sql 应该是:

INSERT INTO Combined_Comments ( [ID],[Comment] ) 
SELECT [Comments_001].[ID],IIf([Comments]<>" ","BR
#" & [Branch Number] & " - " & [Comments],[Comments]) AS [Dup Comment] 
FROM [Comments_001] 
WHERE ((Not (IIf([Comments]<>" ","BR #" & [Branch Number] & " - " & [Comments],[Comments])) not like "*not issue*") AND (([Dup Vin Comments_085].[Dup Ind])<>" "));

我看到很多“非”运算符,并假设双重否定可以满足您的需求。