Bitwise Operations in MS Access

I have a table containing the answer. This answer is a combination of a given list of numbers. (see below)

Possible Values

2 4 8 16 32 64

If I have the answer. Answer 24 - I need some method to work out the only values ​​that could be selected, 16 and 8. I was told if this is where SQL I would use a bitwise operation.

I am pretty good at Access, but I usually don't use VBA code, but I'm open to all ideas.

+4
source share
1 answer

KB194206 ( : " Microsoft Jet SQL. ." ), , VBA.

VBA , VBA .

-:

Function BitAnd(Value1 As Long, Value2 As Long) As Long
    BitAnd = Value1 And Value2
End Function

SQL

WHERE
    BitAnd([someColumn], 64) > 0

, .


. , FlagsTable (FlagValue, FlagName), :

SELECT
  d.Id,
  d.BitField,
  f.FlagName
FROM
  DataTable d
  INNER JOIN FlagsTable f ON BitAnd(d.BitField, o.FlagValue) > 0

"24 16 8".

+8

Source: https://habr.com/ru/post/1544001/


All Articles