I need each record to look for a previous record if the MRN matches and if it does then it needs to look at the service date and if the service date is within 90 days of the previous records discharge date then both of those records need to drop to the report. The same needs to go on until the MRNs no longer match.
MRN PNO Service Dt Discharge Dt
00111 222 01/29/2014 02/26/2014
00111 333 07/21/2014 07/21/2014
00111 444 07/23/2014 07/28/2014
So the crieteris is resulting these 3 records but only want the last two records to populate on the report because 7/21/014 service date on PNO 333 is not within 90 days of the 2/26/14 discharge date on PNO 222 but PNO 444 service date of 7/23/14 is within 90 days of the 7/21/14 discharge date on PNO 333.