如何在 MS-ACCESS 中执行按位运算
在 MSACCESS 内部,我想在查询的 WHERE
子句中使用相对简单的按位运算,如下所示:
SELECT *
FROM Table1
WHERE Column1 (some operator) 8 = 0
这将:
- 返回
Column1
没有设置第 4 位的行,例如 0, 1, 2, ..., 7(所有第 4 位都清零)和 16(即 00010000b) - 排除
Column1
为 8、9、 10、...、15 等
PS:按位运算符与布尔运算不同吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以:
编辑:(其中 b 是要测试的特定位)
OR 在 Access 中不可用,除非您设置 ANSI 模式。
you could:
edit: (where b is the specific bit to test)
OR is not available in Access unless you set ANSI Mode.
如果您可以在 ANSI-92 查询模式(例如,通过更改 Access UI 查询模式或使用 ADO classic 或 ADO.NET 连接到它),使用
BAND
运算符。以下代码示例将其打印到“立即”窗口:
第一种情况 (AND) 将两个数字视为 True 值,因此
True AND True
给出 -1 (True)。我认为 BAND 方法正是您所追求的。If you can run your query in in ANSI-92 Query Mode (e.g. by changing the Access UI Query Mode or by connecting to it using ADO classic or ADO.NET), use the
BAND
operator.The following code sample prints this to the Immediate window:
The first case (AND) treats both numbers as True values, so
True AND True
gives -1 (True). I think the BAND approach is what you're after.在 VBA 中,您可以将布尔运算符应用于数字以执行按位运算
,但是在 SQL 中,这不起作用。但是,您可以编写一个在查询中调用的 VBA 函数。
In VBA, you can apply the Boolean operators to numbers in order to perform bitwise operations
In SQL, however, this does not work. However, you could write a VBA function that you call inside a query.