Author: vinu78
Subject: To display values of multiple rows into singlw row
Posted: Thu Mar 09, 2017 1:20 pm (GMT 5.5)
Hi All,
My requirement is, to have values in multiple rows of a query to be displayed in single row in different column fields.
DB2 Query
If we get single row as output, the expected ouput is
I have tried using LISTAGG function but is not working out.
Please help.
Thanks
Vinu
Subject: To display values of multiple rows into singlw row
Posted: Thu Mar 09, 2017 1:20 pm (GMT 5.5)
Hi All,
My requirement is, to have values in multiple rows of a query to be displayed in single row in different column fields.
DB2 Query
Code: |
SELECT A.PROV_ID, A.SEQ_NO,B.SPEC_CD, FROM TABLEA A, TABLEB B WHERE A.PROV_ID = '12345' AND A.SPEC_CD= B.SPEC_CD ORDER BY A.SEQ_NUM |
Code: |
Current O/p PROV_ID SEQ_NO SPEC_CD 12345 1 AB 12345 2 CD 12345 3 EF |
Code: |
Expected Output PROV_ID SEQ_NO SPEC_1 SPEC_2 111 1 AB CD |
If we get single row as output, the expected ouput is
Code: |
PROV_ID SEQ_NO SPEC_1 SPEC_2 111 1 AB <blanks> |
I have tried using LISTAGG function but is not working out.
Please help.
Thanks
Vinu