Results 1 to 4 of 4
  1. #1
    svesjo is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    1

    Complex query: Find clients with unanswered questions

    I think this got a little bit too complex for me. My problem, very simplified:
    I have the following tables:

    Clients:
    - ID
    - Name

    Events:
    - ID


    - ClientID
    - Type (number, 1 or 2. 1 means question, 2 means answer)
    - Date

    The tables are related by ID - ClientID.

    I want a query that lists all clients that have unanswered questions. I want to do it this way:
    Compare the date of the last event type 1 (question) with the date of the last event type 2 (answer) for each client.
    If the last answer date is earlier than the last question date, it means there are unanswered questions, and I want the client output in the query.
    The query must also work if there are no events of one type or the other.

    Anyone have suggestions, using query designer or sql?

    - svesjo

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    2 part solution. First get the DateDiff between Answer and Question
    Then add that qry to a new query as a Select Totals Query.

    1st qry:
    AQ: DateDiff("d",[AnswerDate],[QuestionDate])
    HTH

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It looks like questions and answers are different records. I feel like this is in the right direction:

    http://www.baldyweb.com/LastValue.htm

    The ones where the last record is a 1 are your unanswered questions. Regarding "The query must also work if there are no events of one type or the other", it would seem irrelevant. If there are no records then there are no unanswered questions.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    svesjo , Good Luck With Your Project!

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

Similar Threads

  1. Query To Show First Date for all Clients
    By UTLee in forum Queries
    Replies: 32
    Last Post: 04-14-2014, 09:14 AM
  2. Query list of clients in date range
    By scorpiogray in forum Queries
    Replies: 2
    Last Post: 05-20-2013, 01:34 PM
  3. Replies: 9
    Last Post: 02-12-2013, 03:14 PM
  4. Query to seperate active/inactive clients
    By csnyder1582 in forum Queries
    Replies: 5
    Last Post: 05-05-2011, 12:01 PM

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