Results 1 to 2 of 2
  1. #1
    pstrahan is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2011
    Posts
    1

    Compare Two types of records from one table

    Hello,

    I am trying to create a query based on a transaction table which compares the time between two types of transactions.



    The initial record would have "A' in the type field and the second record would have "D" in the type field.

    each pair of A and D records would be matched on o_time and idnum fields, and I would want to pull each pair and us the datediff function on c_time, using records marked with A as the intitial time and records marked with D as the followup time.

    Is there any way to accomplish this in a single query or do I need to create two subqueries?

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Yes you can.

    For the purposes of this example:

    The table I set up is Tbl_Test
    The fields were
    IDNum (assuming you are only going to have one A record and one D record for each ID Num)
    Transtype (A, D or anything else, text field)
    O_Time (starting time)
    C_Time (ending time)

    this query will do what you want:

    Code:
    SELECT Tbl_Test.IDNum, Max(IIf([transtype]="A",[O_Time],Null)) AS StartTime, Max(IIf([transtype]="D",[C_Time],Null)) AS EndTime, DateDiff("s",[starttime],[endtime]) AS Expr1
    FROM Tbl_Test
    GROUP BY Tbl_Test.IDNum;

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

Similar Threads

  1. Replies: 6
    Last Post: 07-23-2011, 12:35 PM
  2. Access compare and sum records in two tables
    By piszczel in forum Queries
    Replies: 8
    Last Post: 05-23-2011, 02:07 AM
  3. Compare records in 2 tables
    By RalphJ in forum Access
    Replies: 13
    Last Post: 03-06-2011, 07:43 AM
  4. Field Types for a Linked Table
    By Jeff_J in forum Access
    Replies: 9
    Last Post: 05-05-2009, 07:12 AM
  5. Possible to store user-defined types in table?
    By Binky in forum Programming
    Replies: 0
    Last Post: 11-20-2008, 02:28 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