Results 1 to 6 of 6
  1. #1
    Robeen is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,593

    Sub Query [?] Help.

    * This is an offshoot [progression] of an earlier Query/post that I had help from June on.

    Here is the Table:

    FName Plan Rate
    Bob A 100
    Bob D 100
    Bob C 100
    Bob W 25
    Bob X 25
    Charles X 25
    Charles A 100
    Charles D 100
    Charles W 25

    I need a query that will search the above table for anyone who:


    1. HAS a 'W' or 'X' Plan
    - AND -
    2. DOES NOT HAVE a 'B' or a 'C' Plan.

    What I would like to get back from the query is:
    Charles W 25
    Charles X 25

    Thanks in advance!

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    This will return what you want (substitute your actual Table name in place of "Table1"):
    Code:
    SELECT FName, Plan, Rate
    FROM Table1
    WHERE Plan In ("W","X")
    AND FName in
    (SELECT Table1.FName
    FROM Table1
    GROUP BY Table1.FName
    HAVING Sum(IIf([Plan]="B" Or [Plan]="C",1,0)>=1));

  3. #3
    Robeen is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,593
    Thanks, Joe!
    Is it possible to have an IN statement instead of the 'Or' here: '...IIf([Plan]="B" Or [Plan]="C",1,0 ...' ?
    Reason I ask is that where I have provided W, X - and B, C - there are actually about 15 - 20 Plan types that I have to account for on both sides.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    AFAIK, the IN parameters cannot be dynamic in query object.

    VBA can build the parameter string and apply to form or report Filter property. Review http://allenbrowne.com/ser-50.html

    However, not sure that will be helpful for your situation.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Robeen is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,593
    Thanks, June!
    Appreciate your help . . . again!!

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Reason I ask is that where I have provided W, X - and B, C - there are actually about 15 - 20 Plan types that I have to account for on both sides.
    Might make sense to try to create a table with those lists, and link to them.

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums