I have a weird data issue at work someone asked me to help with and I'm trying to think of the best way to handle it, but have come up with nada so far.
I have a table that looks similar to the example below. In actuality, it extends out to 15 columns (or levels), but that's probably not important here. For each unique id, the hierarchy can differ which would result in some of the columns being null. So for example below, for id = 1, this only has 3 levels associated with it, so columns Level4 and Level5 are null.
_____________________________________________
ID | Level 1 | Level 2 | Level 3 | Level 4 | Level 5
1 | John | Steve | Sue
2 | Tom | Rick | Mary | Tim
3 | Kay | Paul | Jill | John | Steve
4 | Will | Larry | Jack
_____________________________________________
The question is whether there is a way to reverse the order of the columns. For example, for id=1, I would like to have level1 = Sue, level2 = Steve, level 3=John, level4 is null and level 5 is null.
_____________________________________________
ID | Level 1 | Level 2 | Level 3 | Level 4 | Level 5
1 | Sue | Steve | John
2 | Tim | Mary | Rick | Tom
3 | Steve | John | Jill | Paul | Kay
4 | Jack | Larry | Will
_____________________________________________
I have been wondering if there is a way I could coalesce into a single string, and then parse it out in reverse order into separate columns, but not sure. Anyone have any bright ideas?
I have a table that looks similar to the example below. In actuality, it extends out to 15 columns (or levels), but that's probably not important here. For each unique id, the hierarchy can differ which would result in some of the columns being null. So for example below, for id = 1, this only has 3 levels associated with it, so columns Level4 and Level5 are null.
_____________________________________________
ID | Level 1 | Level 2 | Level 3 | Level 4 | Level 5
1 | John | Steve | Sue
2 | Tom | Rick | Mary | Tim
3 | Kay | Paul | Jill | John | Steve
4 | Will | Larry | Jack
_____________________________________________
The question is whether there is a way to reverse the order of the columns. For example, for id=1, I would like to have level1 = Sue, level2 = Steve, level 3=John, level4 is null and level 5 is null.
_____________________________________________
ID | Level 1 | Level 2 | Level 3 | Level 4 | Level 5
1 | Sue | Steve | John
2 | Tim | Mary | Rick | Tom
3 | Steve | John | Jill | Paul | Kay
4 | Jack | Larry | Will
_____________________________________________
I have been wondering if there is a way I could coalesce into a single string, and then parse it out in reverse order into separate columns, but not sure. Anyone have any bright ideas?