Results 1 to 3 of 3
  1. #1
    jbailey4545 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    14

    Query Help

    I have a linked table using ODBC. This is a read only table. I am trying to pull the latest record for patients. Some patients have multiple records and the only way to distinguish them is using the program_seq column. This is a number field starting at 1 and there is no limit to how high it can get. Each record represents when a patient was admitted and discharged. For example I am looking at a patient that has been admitted 3 times and discharged 2 times. The patient is still on the program the program_seq is 3. The primary key is a unique patient number. Any help would greatly be appreciated.



    Eaxmple
    Click image for larger version. 

Name:	data.jpg 
Views:	14 
Size:	15.4 KB 
ID:	8158
    I will also need to pull the newest records even if they have been discharged.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    This uses 2 queries - that select Patient info for patients still on the program

    LatestPatientrecordForPatientStillOnProgram and Patient's who have been discharged.

    The query LatestPatientrecordForPatientStillOnProgram has the following sql

    Code:
    SELECT tblPatient.Client_id, tblPatient.Program_seq, tblPatient.Admit_date, tblPatient.Discharge_Date
    FROM tblPatient
    WHERE (((tblPatient.Discharge_Date) Is Null));
    This query should give you the results required.
    Code:
    SELECT tblPatient.Client_id, tblPatient.Program_seq, tblPatient.Admit_date, tblPatient.Discharge_Date
    FROM tblPatient LEFT JOIN LatestPatientrecordForPatientStillOnProgram ON
     tblPatient.Client_id = LatestPatientrecordForPatientStillOnProgram.Client_id
    WHERE (((tblPatient.Discharge_Date)=
        (select max(discharge_date) from tblPatient as Z where z.client_id =tblPatient.client_id)) AND
         ((LatestPatientrecordForPatientStillOnProgram.Client_id) Is Null))
         
    UNION
    SELECT tblPatient.Client_id, tblPatient.Program_seq, tblPatient.Admit_date, tblPatient.Discharge_Date
    FROM tblPatient
    WHERE (((tblPatient.Discharge_Date) Is Null));

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

Tags for this Thread

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