Results 1 to 3 of 3
  1. #1
    WimDC is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    12

    combining dates in query

    Hi,



    I have a table (or query) with the following fields
    Code:
     
    USER_ID
    CODE        (can be "A" or "B")
    DATUM      (dutch for "date")
    REF_DATE
    REF_EXPLICATION
    Each record HAS data for the first 3 fields; the other fields CAN have data. (of course, each user and each code is linked to a separate table with name, etc...)

    Now, I want to build a query that shows me the records (with user_id, code_id, ref_explication)...
    1) where CODE = "A" and there's no record where the CODE = "B AND where DATE is equal to REF_DATE of the record with code = “A"
    or
    2) where CODE = "A" and there's no REF_DATE
    or
    3) where CODE = "B" and there's no REF_DATE

    Giving the sample database included, I would like to have this result :

    Code:
     
    USER_ID  CODE_ID - DATE        - REF_EXPLICATION_1    -   REF_DATE  -    REF_EXPLICATION_2
       1          A        07/08/2013       01/01/2014          phonecall               (*)
       1          A        08/08/2013       (**)
       1          B        10/08/2013       (***)
    (*) because there's no matching record with code=B AND date=ref_date
    (**) because code=A and there's no ref_date
    (**) because code=B and there's no ref_date

    Can someone help me or give me some suggestions?
    I also split the table in records with code= "A" and in records with code = "B". (see queries) Maybe this can help ?
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    First line in post shows 07/08/2013 but record in table shows 08/07/2013.
    Third line in post shows 10/08/2013 but record in table shows 8/10/2013.
    You should review http://allenbrowne.com/ser-36.html

    Don't really understand these rules.

    Why return record with ref_date 1/12014 and not 8/23/2013?
    Why not return the one record for user_id 2?

    If your rules require each record to consider values of other records for criteria, that is not easy to do.
    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.

  3. #3
    WimDC is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    12
    Hi June7,

    thanks for your reply; the dates in my "output"-code are in Dutch (dd-mm-yyyy), but I think you opened my database in an English version.

    In the meanwhile, I found an answer for my problem : http://www.access-programmers.co.uk/...29#post1288129

    Wim

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

Similar Threads

  1. Replies: 14
    Last Post: 07-22-2013, 12:39 PM
  2. Combining rows in query?
    By rev in forum Queries
    Replies: 2
    Last Post: 04-23-2012, 08:47 AM
  3. Query input dates for range of dates in two fields
    By kagoodwin13 in forum Queries
    Replies: 3
    Last Post: 02-13-2012, 04:25 PM
  4. Query for combining records
    By alpinegroove in forum Queries
    Replies: 6
    Last Post: 01-28-2011, 07:29 AM
  5. Combining Tables by Query
    By jlclark4 in forum Queries
    Replies: 9
    Last Post: 01-25-2011, 12:19 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