Could any of you please provide update querry for the following scenario.
Requiremnt:
1. Update the UNIQUE_ID of record ( same Identifier and Identifier_code where END_Date is not null) with the UNIQUE_ID of the record (( same Identifier and Identifier_codewhere END_Date is null).
2. If More than one NULL in END_date then update UNIQUE_ID with max(EFFective_Date) of UNIQUE_ID
Source data
---------------
UNIQUE_ID | Identifier | Identifier_code | EFFective_Date | END_Date |
1 | 777 | abc | 2/14/2014 11:15 | 2/28/2014 9:00 |
1 | 777 | abc | 2/21/2014 9:00 | 3/7/2014 9:02 |
2 | 777 | abc | 2/28/2014 9:00 | 3/14/2014 9:02 |
2 | 777 | abc | 3/7/2014 9:02 | 3/14/2014 9:02 |
2 | 777 | abc | 3/14/2014 9:02 | NULL |
5 | 888 | xyz | 2/14/2014 11:15 | 2/28/2014 9:00 |
5 | 888 | xyz | 2/21/2014 9:00 | 3/7/2014 9:02 |
5 | 888 | xyz | 2/28/2014 9:00 | 3/14/2014 9:02 |
6 | 888 | xyz | 3/7/2014 9:02 | NULL |
7 | 888 | xyz | 3/14/2014 9:02 | NULL |
OutPUT . --------- | ||||
UNIQUE_ID | Identifier | Identifier_code | EFFective_Date | END_Date |
2 | 777 | abc | 2/14/2014 11:15 | 2/28/2014 9:00 |
2 | 777 | abc | 2/21/2014 9:00 | 3/7/2014 9:02 |
2 | 777 | abc | 2/28/2014 9:00 | 3/14/2014 9:02 |
2 | 777 | abc | 3/7/2014 9:02 | 3/14/2014 9:02 |
2 | 777 | abc | 3/14/2014 9:02 | NULL |
7 | 888 | xyz | 2/14/2014 11:15 | 2/28/2014 9:00 |
7 | 888 | xyz | 2/21/2014 9:00 | 3/7/2014 9:02 |
7 | 888 | xyz | 2/28/2014 9:00 | 3/14/2014 9:02 |
7 | 888 | xyz | 3/7/2014 9:02 | NULL |
7 | 888 | xyz | 3/14/2014 9:02 | NULL |
Thanks in advance.
.