- Requirement 1:
- TO UNPIVOT the given data (as shown below) in a row into multiple rows (should exclude the null values) as shown in Output required.
- The GRADES column can have multiple values (the code has to loop until the complete set is split or unpivoted.
| ID |
GRADES |
| 123 |
[A,B,C,C,D] |
| 456 |
[A,,D] |
| ID |
GRADES |
| 123 |
A |
| 123 |
B |
| 123 |
C |
| 123 |
C |
| 123 |
D |
| 456 |
A |
| 456 |
D |
- Requirement 2:
- Use the unpivoted data (as shown below) & select only the distinct records from them and pivot them back to load into a different table. as shown in Output required.
| ID |
GRADES |
| 123 |
A |
| 123 |
B |
| 123 |
C |
| 123 |
C |
| 123 |
D |
| 456 |
A |
| 456 |
D |
| ID |
GRADES |
| 123 |
[A,B,C,D] |
| 456 |
[A,D] |
I tried to create a procedure using substring, locate, instr to split the values and concat them back but unable to achieve the required output. Currently stuck with the logic.
For Requirement 1:
For Requirement 2: