I have 3 tables with data structures as shown below:
TBL-1 (contains some current data about tasks)
TskID TskDescription AreaID
9345 ItemDescription-1 Area-1
4940 ItemDescription-2 Area-2
TBL-2 (contains descriptions of what area is responsible for a task)
AreaID AreaDescription
Area-1 AreaDescription-1
Area-2 AreaDescription-2
TBL-3 (contains trans history about tasks)
TskID FromState ToState TransDate
9345 State-A State-B Date-1
9345 State-B State-C Date-2
9345 State-C State-D Date-3
4990 State-A State-B Date-5
4940 State-B State-C Date-6
4940 State-C State-B Date-7
4940 State-B State-C Date-8
4940 State-C State-D Date-9
What I need is a single row returned for each of the two TskIDs which contain the following values:
9345, ItemDescription-1, AreaDescription-1, Date-2, Date-3
4940, ItemDescription-2, AreaDescription-2, Date-8, Date-9
The problem I'm having concerns TBL-3. A task can iterate through a state more than once (as seen in task 4940, ToState B&C). I am only interested in retrieving the most recent date of ToState values C and D.
How do I create a single row showing the max(TransDate) for ToState values of C and D for a particular TskID?
TBL-1 (contains some current data about tasks)
TskID TskDescription AreaID
9345 ItemDescription-1 Area-1
4940 ItemDescription-2 Area-2
TBL-2 (contains descriptions of what area is responsible for a task)
AreaID AreaDescription
Area-1 AreaDescription-1
Area-2 AreaDescription-2
TBL-3 (contains trans history about tasks)
TskID FromState ToState TransDate
9345 State-A State-B Date-1
9345 State-B State-C Date-2
9345 State-C State-D Date-3
4990 State-A State-B Date-5
4940 State-B State-C Date-6
4940 State-C State-B Date-7
4940 State-B State-C Date-8
4940 State-C State-D Date-9
What I need is a single row returned for each of the two TskIDs which contain the following values:
9345, ItemDescription-1, AreaDescription-1, Date-2, Date-3
4940, ItemDescription-2, AreaDescription-2, Date-8, Date-9
The problem I'm having concerns TBL-3. A task can iterate through a state more than once (as seen in task 4940, ToState B&C). I am only interested in retrieving the most recent date of ToState values C and D.
How do I create a single row showing the max(TransDate) for ToState values of C and D for a particular TskID?