foxtrot123
Registered User.
- Local time
- Today, 06:52
- Joined
- Feb 18, 2010
- Messages
- 57
Hope I'm not wearing out my welcome. Just suddenly facing a lot of tricky queries that are boggling my mind. Any advice or tips much appreciated.
I have data on surgeries. A patient goes in and gets one or more metal implants. I also have a flag to indicate his first surgery.
If the patient comes in for a subsequent surgery, and has more implants added, I need to flag his first surgery as "Needed More" and his subsequent surgery as "Got More". This occurs with Pts 2 and 3.
Original Data
So the query would return:
New Data
Any suggestions? It seems the logic goes like this:
Within PtID, for the first surgery (FirstSurg - Yes), if ImplantsAdded >= 1, and a subsequent surgery has ImplantsAdded >=1 (subsequent SurgDate > the previous SurgDate) AND (ImplantsAdded =>1), then:
Status for previous surgery = "NeededMore"
Status for subsequent surgery = "GotMore"
Any suggestions about how to tackle this?
I have data on surgeries. A patient goes in and gets one or more metal implants. I also have a flag to indicate his first surgery.
If the patient comes in for a subsequent surgery, and has more implants added, I need to flag his first surgery as "Needed More" and his subsequent surgery as "Got More". This occurs with Pts 2 and 3.
Original Data
Code:
PtID SurgDate FirstSurg SurgID ImplantsAdded
1 1/1/08 Yes 1 1
1 5/1/09 2
--------------------------------------------------------
2 1/1/07 Yes 3 2
2 5/1/07 4 1
--------------------------------------------------------
3 1/1/07 Yes 5 1
3 5/1/07 6
3 7/1/07 7 1
New Data
Code:
PtID SurgDate FirstSurg SurgID ImplantsAdded Status
1 1/1/08 Yes 1 1
1 5/1/09 2
--------------------------------------------------------
2 1/1/07 Yes 3 2 Needed More
2 5/1/07 4 1 Got More
--------------------------------------------------------
3 1/1/07 Yes 5 1 Needed More
3 5/1/07 6
3 7/1/07 7 1 Got More
Within PtID, for the first surgery (FirstSurg - Yes), if ImplantsAdded >= 1, and a subsequent surgery has ImplantsAdded >=1 (subsequent SurgDate > the previous SurgDate) AND (ImplantsAdded =>1), then:
Status for previous surgery = "NeededMore"
Status for subsequent surgery = "GotMore"
Any suggestions about how to tackle this?