I am having some problems filtering some records that aren't distinct. Here is my scenario:
Example record set in this format:
MessageID, ReceiveDate, ActionDate1, ActionDate2, SendDate, Name, Code, Description
Here is 6 records from the table I am pulling from. Notice some have same MessageID, the only difference is a different ActionDate1. See below for question.
82285 2003-06-12 19:49:34 2003-06-15 08:48:53 2003-06-15 11:33:26 2003-06-15 11:33:26 XYZName Code Description
82285 2003-06-12 19:49:34 2003-06-14 15:12:17 2003-06-15 11:33:26 2003-06-15 11:33:26 XYZName Code Description
82285 2003-06-12 19:49:34 2003-06-15 07:24:23 2003-06-15 11:33:26 2003-06-15 11:33:26 XYZName Code Description
82301 2003-06-12 20:00:01 2003-06-14 15:12:17 2003-06-15 09:47:09 2003-06-15 09:47:09 XYZName Code Description
82301 2003-06-12 20:00:01 2003-06-15 08:52:07 2003-06-15 09:47:09 2003-06-15 09:47:09 XYZName Code Description
82302 2003-06-12 20:00:02 2003-06-15 08:52:07 2003-06-15 11:39:27 2003-06-15 11:39:27 XYZName Code Description
Because ActionDate1 can change on the same messageID, it creates multiple records with the same messageID. What I want to do, is return only records with distinct messageIDs. And, for those records that have the same messageID, I want to return the record that has the most recent ActionDate1.
Can anyone recommend a way to do this? I am thinking I am going to have to use a cursor, but am not completely clear on the logic that will have to be used in it.
Thanks
Example record set in this format:
MessageID, ReceiveDate, ActionDate1, ActionDate2, SendDate, Name, Code, Description
Here is 6 records from the table I am pulling from. Notice some have same MessageID, the only difference is a different ActionDate1. See below for question.
82285 2003-06-12 19:49:34 2003-06-15 08:48:53 2003-06-15 11:33:26 2003-06-15 11:33:26 XYZName Code Description
82285 2003-06-12 19:49:34 2003-06-14 15:12:17 2003-06-15 11:33:26 2003-06-15 11:33:26 XYZName Code Description
82285 2003-06-12 19:49:34 2003-06-15 07:24:23 2003-06-15 11:33:26 2003-06-15 11:33:26 XYZName Code Description
82301 2003-06-12 20:00:01 2003-06-14 15:12:17 2003-06-15 09:47:09 2003-06-15 09:47:09 XYZName Code Description
82301 2003-06-12 20:00:01 2003-06-15 08:52:07 2003-06-15 09:47:09 2003-06-15 09:47:09 XYZName Code Description
82302 2003-06-12 20:00:02 2003-06-15 08:52:07 2003-06-15 11:39:27 2003-06-15 11:39:27 XYZName Code Description
Because ActionDate1 can change on the same messageID, it creates multiple records with the same messageID. What I want to do, is return only records with distinct messageIDs. And, for those records that have the same messageID, I want to return the record that has the most recent ActionDate1.
Can anyone recommend a way to do this? I am thinking I am going to have to use a cursor, but am not completely clear on the logic that will have to be used in it.
Thanks