不像“ * TEST *”,<>“ TEST”,不像“ * TEST *”,不像“ * TEST”,不像“ TEST *”,不存在()

时间:2018-09-25 03:53:19

标签: sql ms-access

在使用Design&SQL的访问查询中,我尝试了以下各项,但均未成功。似乎没有什么可以过滤掉[Status] =“ TEST”或“ TEST ”的任何内容,因为'Test'可能在[Status]字段中的任何位置。

Not like "*TEST*" 
<> "TEST"
Not Like "*TEST*"
Not Like "*TEST" 
Not Like "TEST*"
Not Exists (SELECT MainData.* WHERE MainData.Status = "TEST")

全长

SELECT [MainData].*
FROM [Main Data]
WHERE ((([MainData].AMOUNT)<[MainData]![OtherAmount]) 
AND (([MainData].Status) Not Like "TEST"));

一切正常,直到我插入“ TEST”之类的

先谢谢您!

2 个答案:

答案 0 :(得分:1)

由于为空值,因此您的查询找不到任何内容。您可以使用NZ函数来消除此问题。

SELECT [MainData].*
FROM [MainData]
WHERE (( ([MainData].AMOUNT)<[MainData]![OtherAmount]) 
    AND (( NZ([MainData].Status,"") ) NOT Like "*TEST*"));

答案 1 :(得分:0)

在Access SQL中,正确的语法是

'Excludes everything with "Test" in it (12test34)
SELECT * FROM [Main Data] WHERE [Main Data].Status Not Like "*Test*"

'Excludes everything that starts with "Test" (test34)
SELECT * FROM [Main Data] WHERE [Main Data].Status Not Like "Test*"

'Excludes everything that ends with "Test" (12test)
SELECT * FROM [Main Data] WHERE [Main Data].Status Not Like "*Test"