Date Crunch

Database

Date Crunch

Hi, I've below problem and mulling over for a solution, any thoughts would be greatly appreciated.

I've a table with 4 columns: parameter, Priority, start-dt and End-dt. What I am looking for is (priority goes 1 - 5, 1-lowest and 5-highest). I should crunch my parm dates based on the priority. Below is sample input and output:

Input:

parm pri start(mm-dd-yyyy) end(mm-dd-yyyy)

105   1   1/1/2015               12/31/2015

105   2   1/1/2015               3/31/2015

105   2   4/2/2015               4/28/2015

Output

parm pri start(mm-dd-yyyy) end(mm-dd-yyyy)

105   2   01/01/2015        03/31/2015

105   1   04/01/2015        04/01/2015

105   2   04/02/2015        04/28/2015

105   1   04/29/2015        12/31/2015

i.e. give priority to the 2-pri dates (as the parm value would be different at different priority levels. I didn't mention VALUE column in my above example assuming it would be nothing to do with the logic).

Please throw some thoughts if you come across this kind of problem ever and let me know if you feel I miss any details to provide here.

Thanks

Rai