I am working on a project to create SLAs for different orders. To do this, I need to merge multiple rows into a single row, although there are times it will be on more than 1 row. Here is how the data is currently set up:
OrderNumber | Stage1 | Stage2 | Stage3 | Stage4 |
=================================================
1 |1/1/2016|*NULL* |*NULL* | *NULL*
1 |*NULL* |2/1/2016|*NULL* | *NULL*
1 |*NULL* |*NULL* |3/1/2016| *NULL*
1 |*NULL* |*NULL* |*NULL* | 4/1/2016
1 |*NULL* |5/1/2016|*NULL* | *NULL*
The way I am hoping to see the data is like this:
OrderNumber | Stage1 | Stage2 | Stage3 | Stage4 |
=================================================
1 |1/1/2016|2/1/2016|3/1/2016| 4/1/2016
1 |1/1/2016|5/1/2016|*NULL* | *NULL*
OR
OrderNumber | Stage1 | Stage2 | Stage3 | Stage4 |
=================================================
1 |1/1/2016|2/1/2016|3/1/2016| 4/1/2016
1 |*NULL* |5/1/2016|*NULL* | *NULL*
There are two problems I see, 1) Merging multiple rows into a single row and 2) If a value shows up in a column more than once, displaying it in a new row (ideally with values from previous stages appearing in earlier columns, but this isn't required).
The closest solution I have found is this: Merge two rows in SQL , but it did not work for this problem.
Any help would be greatly appreciated.
Edit Updated Tags