foxtrot123
Registered User.
- Local time
- Today, 12:31
- Joined
- Feb 18, 2010
- Messages
- 57
I have a table, tblVisits, holding patient's pre and post surgery visits:
And another table holding patient's surgeries (each patient will have only one surgery)
I need to compare these two tables and create a variable that indicates which pre-surgery visit date (i.e., VisitDate < SurgeryDate) is closest to the surgery date. In the above example, it would return:
Any suggestions? I've tried various MIN and MAX approaches and can't seem to get it right.
Code:
PatientID VisitDate
1 1/5/12
1 3/10/12
1 9/1/13
2 ...
Code:
PatientID SurgeryDate
1 4/1/12
2 ...
Code:
PatientID VisitDate ClosestToSurgery
1 1/5/12
1 3/10/12 Yes
1 9/1/13
2 ...