Solved

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

Posted on 2015-02-19
5
180 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now