如何在 SQL MSAccess 中对同一字段使用“喜欢”和“不喜欢”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10107484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use "like" and "not like" in SQL MSAccess for the same field?
提问by Totty.js
I would like to filter all the rows that are:
我想过滤所有的行:
field like "*AA*" and field not like "*BB*"
But this is returning everything instead of showing all the rows that contains AA
and doesn't contain BB
.
但这将返回所有内容,而不是显示包含AA
和不包含的所有行BB
。
well now it works like expected, just restarted ms access...
好吧,现在它按预期工作,只是重新启动了 ms 访问...
Sorry for my typo... :s updated
抱歉我的错别字... :s 更新
回答by Paddy
Try this:
尝试这个:
filed like "*AA*" and filed not like "*BB*"
回答by Ponytell
What I found out is that MS Access will reject --Not Like "BB*"-- if not enclosed in PARENTHESES, unlike --Like "BB*"-- which is ok without parentheses.
我发现 MS Access 会拒绝 --Not Like "BB*" -- 如果没有包含在括号中,不像 --Like "BB*" -- 没有括号也可以。
I tested these on MS Access 2010 and are all valid:
我在 MS Access 2010 上测试了这些,并且都是有效的:
Like "BB"
(Like "BB")
(Not Like "BB")
喜欢“ BB”
(比如“ BB”)
(不像“ BB”)
回答by Alex K.
Simply restate the target field & condition;
只需重申目标字段和条件;
where (field like "*AA*" and field not like "*BB*")
回答by Diego
what's the problem with:
有什么问题:
field like "*AA*" and field not like "*BB*"
it should be working.
它应该工作。
Could you post some example of your data?
你能发布一些你的数据的例子吗?
回答by Roy
Not sure if this is still extant but I'm guessing you need something like
不确定这是否仍然存在,但我猜你需要类似的东西
((field Like "AA*") AND (field Not Like "BB*"))
回答by Serge
If you're doing it in VBA (and not in a query) then: where field like "AA" and field not like "BB" then would not work.
如果您在 VBA 中(而不是在查询中)执行此操作,则: where 字段像“ AA”和字段不像“ BB”那么将不起作用。
You'd have to use: where field like "AA" and field like "BB" = false then
你必须使用: where 字段像“ AA”和字段像“ BB” = false 那么