Solved

MS-Access - Determining if the next record meets a criteria

Posted on 2015-02-19
5
189 Views
Last Modified: 2015-02-19
I have attached a list of sample data I have to evaluate for repeat admissions within 30 days of the last admission date.  The data is organized by Unit Number and Admission Dates in a descending order.  If the subsequent admission date for the same Unit Number is within 30 days of the current  record's admission date, then it should be marked as "Y" for readmission.

Can this be reflected in a query?

Thanks

Glen
lACEdATA.xlsx
0
Comment
Question by:GPSPOW
  • 3
  • 2
5 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 40620227
You use UnitNumber, not AccountNumber to identify readmission?

You can do something like:

SELECT T.UnitNumber, T.AccountNumber, T.AdmitDateTime
, Max(T2.AdmitDateTime) as PrevAdmitDate
FROM yourTable as T
LEFT JOIN yourTable as T2
ON T.UnitNumber = T2.UnitNumber
AND T.AdmitDateTime > T2.AdmitDateTime
GROUP by T.UnitNumber, T.AccountNumber, T.AdmitDateTime

This would give you each admittance and the previous admittance for that particular UnitNumber.  You could then wrap that up as a subquery to get the indication of whether it is a readmittance.

Select subQ.UnitNumber, SubQ.AccountNumber
subQ.AdmitDateTime, subQ.PrevAdmitDate
, iif(IsNull([PrevAdmitDate]), "No", iif(DateDiff("d", subQ.PrevAdmitDate, subQ.AdmitDateTime) <= 30, "Yes", "No")) as Readmit
FROM (
SELECT T.UnitNumber, T.AccountNumber, T.AdmitDateTime
, Max(T2.AdmitDateTime) as PrevAdmitDate
FROM yourTable as T
LEFT JOIN yourTable as T2
ON T.UnitNumber = T2.UnitNumber
AND T.AdmitDateTime > T2.AdmitDateTime
GROUP by T.UnitNumber, T.AccountNumber, T.AdmitDateTime
) as SubQ
0
 

Author Closing Comment

by:GPSPOW
ID: 40620271
I had to reverse the two dates in the datediff function and it worked perfectly.

The UnitNumber is the patient Medical Record number which stays with the patient no matter how many times he or she is admitted.  The account number changes with every admit.  So I am looking when the UnitNumber matches for subsequent admissions.

Thanks

Glen
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40620288
glad to be of assistance.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40620290
actually, you might want to use:

IIF(DateDiff("d", NZ([PrevAdmitDate], [AdmitDate] - 31), [AdmitDateTime]) <=30, "Yes", "No") as Readmit

This should work better as it handles the NULL [PrevAdmitDate] inside an NZ function instead of another IIF( ) statement.
0
 

Author Comment

by:GPSPOW
ID: 40620295
Thanks
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question