Results 1 to 8 of 8
  1. #1
    AnAverageDave is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    2

    Question on Merging Two Tables with Approximate Matches Instead of Exact Matches

    Hi, the problem I am currently trying to solve requires some background, so please bear with me:

    I am a medical student working on a retrospective study of some medical records, and one piece of data that I am collecting is time spent in the operating room for a specific operation. All of the other information that I am collecting comes from "program X" (our hospital's medical record software) where I will be manually reading through notes to find the information that I need. However, this one piece of information is stored on "program Y" (medical record software specific to the operating rooms). Unfortunately, I do not have access to "program Y," so I talked to our medical records people, and their solution was to have the program dump the relevant information into an Excel table that they were able to give me. The problem is that what they were able to give me was a list of every procedure done at our hospital for the time span that I indicated, and that added up to just under 76,000 entries. Only 2,400 of those entries are ones that I need. Now I need to correlate the data.

    I currently have 2 Excel tables: one table (Table 1) with the MRN (medical record number) and DC_DATE (discharge date from the hospital), and another table (Table 2) with MRN, OP_DATE (date of the operation), and OP_TIME (time spent in operating room). My end goal is a table with MRN, DC_DATE, OP_DATE, and OP_TIME.

    Problem 1: I can't just link the two via MRN because the patient could have had more than one operation within the specified time period, so they could have more than one entry in Table 2. In order to guarantee that I am matching the correct entries, I also need to link DC_DATE from Table 1 with OP_DATE from Table 2.

    Problem 2: DC_DATE and OP_DATE may not be the same day because the patient may have had the operation and stayed in the hospital for another couple days.


    Question: Is it possible to link two tables with approximate matches? For example, can I link MRN and DC_DATE from Table 1 to the MRN and closest OP_DATE (relative to DC_DATE) from table 2? Alternatively, can I set a parameter that links the DC_DATE with an OP_DATE that falls within a range, e.g. within 7 days prior to the DC_DATE?

    I really appreciate your help! Also, if anyone has an alternative method that might work, I'm all ears. I just don't want to spend countless hours going through and manually looking up these numbers when I'm already going to have to be looking up a ton of other information from the actual patient charts.

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    short answer is yes in principle (using a mixture of linking and criteria) however you need to clarify closest - is that closest before? or after? or just nearest to either way?

  3. #3
    AnAverageDave is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    2
    I appreciate your help Ajax!

    It would be closest before, as the patient can't get discharged until after their procedure. Thus, OP_DATE is always before DC_DATE. How would I appropriately list the criteria?

  4. #4
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    something like this


    Code:
    SELECT *
    FROM Table1 inner join table2
    ON table1.mrn=table2.mrn
    WHERE table2.OPDate = (SELECT Max(OPDate) FROM Table2 as T WHERE mrn=Table1.mrn AND OPDate<=DCDate)

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    @Ajax
    I don't know, since I haven't worked with sub queries much, but isn't there a "T" missing in the sub query?
    Code:
    WHERE table2.OPDate = (SELECT Max(OPDate) FROM Table2 as T WHERE T.mrn = Table1.mrn AND OPDate<=DCDate)

    I came up with a different query
    Code:
    SELECT T1.MRN, T2.OP_Date, T1.DC_Date
    FROM Table1 AS T1 INNER JOIN Table2 AS T2 ON T1.MRN = T2.MRN
    WHERE T1.DC_Date Between T2.OP_Date And T2.OP_Date+7;
    but I think yours is better because I hard coded dc_date within op_date + 7 days.

  6. #6
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    but isn't there a "T" missing in the sub query?
    Not required since T is the default

    same as

    SELECT afield from atable

    you don't need to say

    SELECT atable.afield from atable

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Thanks, Ajax. Learned something new about aliases.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I'd like to hear more about MRN. It seems that the MRN on the 2 tables should be consistent. Do you have a working definition/description of MRN?

    Perhaps some sample data would clarify the situation.

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

Similar Threads

  1. Replies: 11
    Last Post: 02-21-2016, 02:34 PM
  2. Finding matches between two TABLES
    By DAbbot in forum Queries
    Replies: 4
    Last Post: 11-13-2015, 08:28 AM
  3. Query for not exact matches in two tables
    By FrankBone in forum Queries
    Replies: 1
    Last Post: 06-03-2015, 12:49 AM
  4. Option is True if Barcode matches
    By SmugglersBlues in forum Programming
    Replies: 3
    Last Post: 02-01-2013, 04:59 PM
  5. Partial Matches in a Parameter Value
    By Darkladymelz in forum Access
    Replies: 18
    Last Post: 03-06-2012, 12:02 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