I have implemented following query to pivot col_nm from row to column:
select grp_id,orig_businesseffectivedate,
max(case when col_nm= 'bus_seg_cd' then col_val end) as bus_seg_cd,
max(case when col_nm= 'dft_insur_cd' then col_val end) as dft_insur_cd,
max(case when col_nm= 'drc_indrct_ind' then col_val end) as drc_indrct_ind,
max(case when col_nm= 'ifrs9_stream' then col_val end) as ifrs9_stream,
max(case when col_nm= 'stff_loan_cd' then col_val end) as stff_loan_cd,
max(case when col_nm= 'loan_prps_cd' then col_val end) as loan_prps_cd,
max(case when col_nm= 'org_bu' then col_val end) as org_bu,
max(case when col_nm= 'prime_ind' then col_val end) as prime_ind,
max(case when col_nm= 'rcrr_prd_cd' then col_val end) as rcrr_prd_cd,
max(case when col_nm= 'scrty_ind' then col_val end) as scrty_ind,
max(case when col_nm= 'stff_loan_cd' then col_val end) as stff_loan_cd
from crz_shrd.cpp_rcrr_prd_mappng_grp_dtl
group by grp_id,orig_businesseffectivedate
and following is the output which looks correct: result of the query
I wonder if col_nm gets a new value, is there a way to handle it dynamically or make pivoting generic?