Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2010
    Posts
    6

    Unanswered: query field with multiple values

    hello guys,

    i need a query that will do a dictionary like lookup in an ms-access database with vb6. The database contains a table and two fields A & B.

    for example if A contains 1,2,3,4,5,6 and the corresponding values in B is a,b,c,d,e,f

    then i will pass values 1,4,6 to the query, and it should return a,d,f

    somthing like

    SELECT * FROM table WHERE A = 1 and 2 and 6

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    I won't even ask about the
    will do a dictionary like lookup in an ms-access database with vb6
    But in Access the proper syntax for

    WHERE A = 1 and 2 and 6

    would be

    WHERE A = 1 and A = 2 and A = 6

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Dec 2010
    Posts
    6
    what i really mean is like for example if field A contains 1,2,3,4,5,6 and the corresponding values in field B is a,b,c,d,e,f

    then i will pass values 1,4,6 to the query, and it should return a,d,f

    somthing like

    SELECT * FROM table WHERE A = 1 and 2 and 6

    if it possible i return both the values passed with the result. something like

    A-B
    1,a
    4,d
    6,f

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try:
    SELECT Table.B FROM Table WHERE Table.A IN ( 1, 2, 6 );
    Expressions such as:
    Code:
    WHERE A = 1 and A = 2 and A = 6
    are contradictory and will always evaluate to FALSE: something cannot be equal to 1 and also be equal to 2 and also be equal to 6. The proper logical operator in such a case would be OR:
    Code:
    WHERE A = 1 OR A = 2 OR A = 6
    You can get both columns back with:
    Code:
    SELECT Table.A, Table.B FROM Table WHERE Table.A IN ( 1, 2, 6 );
    Have a nice day!

  5. #5
    Join Date
    Dec 2010
    Posts
    6
    thanks, i'll try it and let you know.

Posting Permissions

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