Is this possible? For example, I want to get the latest date for the value of PC2Date,Re2Date,Rp2Date then the resut will be the value of PC2 or Re2 or Rp2.
I want to add another column for the Result of the sorting.
+------------------------------------------------------------------------------------------------------+
|id | Pc2 | Pc2Date | Re2 | Re2Date |Rp2 | Rp2Date |
--------------------------------------------------------------------------------------------------------
|aaa | PCRej | 2016-12-28 07:44:08.000 | LARej |2016-11-18 20:24:14.000 |RpRej |2016-11-19 19:14:06.000|
|bbb | PCRej | 2016-11-09 20:57:15.000 | NULL |NULL |RpGd |2016-11-12 12:23:51.000|
|ccc | PCRej | 2016-10-06 20:07:04.000 | NULL |NULL |NULL |NULL |
|ddd | PCRej | 2016-10-27 14:15:32.000 | NULL |NULL |RpRej |2016-11-02 14:59:30.000|
|eee | PCRej | 2016-10-24 19:30:22.000 | LARej |2016-11-03 09:27:12.000 |NULL |NULL |
|fff | PCRej | 2016-10-24 19:30:22.000 | LAGd |2017-01-03 08:27:16.000 |NULL |NULL |
So for that sample Condition the result will be something like this:
Output
+--------------------------------------------------------------------------------------------------------------+
|id | Pc2 | Pc2Date | Re2 | Re2Date |Rp2 | Rp2Date | Result|
----------------------------------------------------------------------------------------------------------------
|aaa | PCRej | 2016-12-28 07:44:08.000 | LARej |2016-11-18 20:24:14.000 |RpRej |2016-11-19 19:14:06.000| PCRej |
|bbb | PCRej | 2016-11-09 20:57:15.000 | NULL |NULL |RpGd |2016-11-12 12:23:51.000| RpRgd |
|ccc | PCRej | 2016-10-06 20:07:04.000 | NULL |NULL |NULL |NULL | PCRej |
|ddd | PCRej | 2016-10-27 14:15:32.000 | NULL |NULL |RpRej |2016-11-02 14:59:30.000| RPRej |
|eee | PCRej | 2016-10-24 19:30:22.000 | LARej |2016-11-03 09:27:12.000 |NULL |NULL | LARej |
|fff | PCRej | 2016-10-24 19:30:22.000 | LAGd |2017-01-03 08:27:16.000 |NULL |NULL | LAgd |
TIA!
PCRejby using the three date fields as an input?