Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2012
    Posts
    3

    Red face Unanswered: query using binary style in the WHERE side?

    I'm trying to filter my results using the following "binary style" query:

    SELECT * FROM table_1 WHERE ((field_1 AND 7) = field_1)

    instead of

    SELECT * FROM table_1 WHERE ((field_1 = 1) or (field_1 = 2) or (field_1 = 4))

    Any sugestions?

    Thanks!

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    The Jet Engine will always interpret AND and OR as logical operators. You can create a public function (in an independent module):
    Code:
    Public Function BitAnd(ByVal Value1 As Variant, ByVal Value2 As Variant) As Variant
    
        BitAnd = Value1 And Value2
        
    End Function
    Then use:
    Code:
    SELECT Table_1.*
    FROM Table_1
    WHERE (BitAnd([Field_1],7)=[Field_1]);
    Notice that the need for this kind of criteria is a sign that your database probably violates the first normal form.
    Have a nice day!

  3. #3
    Join Date
    Mar 2012
    Posts
    3

    Thanks

    Thanks for the idea, I will try this.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •