foxtrot123
Registered User.
- Local time
- Today, 03:37
- Joined
- Feb 18, 2010
- Messages
- 57
I have data like so. This is from a junction table that creates a many-to-many between tblPatients and tblEvents. PtEventID is the PK, PtID is a FK to tblPatients, and EventID is a FK to tblEvents.
(I'm showing Event to make it easier to understand.)
etc.
The above patient had two surgeries. After the first surgery - but before his second surgery - he had two complications. On the day of his second surgery, he had one complication.
I need to use the EventDate to associate the complications to the surgical event that came immediately before it (or occurred on the same day). This is obviously better done ahead of time with a different table structure, but this is what I'm working with.
The query should return something like this:
Any sugggestions for going about this? Thank you.
(I'm showing Event to make it easier to understand.)
Code:
PtEventID PtID EventID Event EventDate
1 1 1 Office 1/1/08
2 1 1 Office 1/5/08
3 1 2 Surgery 2/1/08
4 1 3 ComplicABC 2/2/08
5 1 4 ComplicXYZ 2/8/08
6 1 2 Surgery 3/10/08
7 1 3 ComplicABC 3/10/08
The above patient had two surgeries. After the first surgery - but before his second surgery - he had two complications. On the day of his second surgery, he had one complication.
I need to use the EventDate to associate the complications to the surgical event that came immediately before it (or occurred on the same day). This is obviously better done ahead of time with a different table structure, but this is what I'm working with.
The query should return something like this:
Code:
PtID EventID Event EventDate Complication ComplicationDate
1 1 Office 1/1/08
1 1 Office 1/5/08
1 2 Surgery 2/1/08 ComplicABC 2/2/08
1 2 Surgery 2/1/08 ComplicXYZ 2/8/08
1 2 Surgery 3/10/08 ComplicABC 3/10/08
etc.