I have a table in format
Data:
ID Sev1 Sev2 Sev3
ABC 0.45 1 1
PQR 0.45 1 2
XYZ 0.45 1 1
I want to change this to the new format as below by using horizontal pivot . How can i get column names ( severity ) as well along with its data
Expected Output:
ID Severity Values
ABC Sev1 0.45
ABC Sev2 1
ABC Sev3 1
PQR Sev1 0.45
PQR Sev2 1
PQR Sev3 2
XYZ Sev1 0.45
XYZ Sev2 1
XYZ Sev3 1
To bring the column names as rows and add along with the corresponding values
After converting using horizontal pivot and after then i am using CDC stage to define if its an insert or update record with CDC_Changecode = 1 or CdcChangeCode = 3. Please find below sample data
ID Severity Values CDCCode
ABC Sev1 0.45 1
ABC Sev2 1 1
ABC Sev3 1 1
PQR Sev1 0.45 3
PQR Sev2 1 3
PQR Sev3 2 3
XYZ Sev1 0.45 3
XYZ Sev2 1 3
XYZ Sev3 1 3
Once i get this output after using CDC stage ( 1 = Insert record , 3 = Update record ) then i want to convert them columns to rows using vertical pivot. When
Expected output after vertical pivot
CDC Code = 1 ( insert record - i am trying to get below data as ouput )
ID Sev1 Sev2 Sev3
ABC 0.45 1
PQR 1
CDC Code = 3 ( Update record - i am trying to get below data as ouput )
ID Sev1 Sev2 Sev3
ABC 1
PQR 0.45 2
XYZ 0.45 1 1