Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
To display values of multiple rows into singlw row

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 151
Location: India

PostPosted: Thu Mar 09, 2017 1:20 pm    Post subject: To display values of multiple rows into singlw row
Reply with quote

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
Back to top
View user's profile Send private message

Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1922
Location: UK

PostPosted: Thu Mar 09, 2017 3:51 pm    Post subject:
Reply with quote

Someone is sure to ask:
    What happened to the EF from the third row?
    Why has PROV_ID changed from 12345 to 111?
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 151
Location: India

PostPosted: Thu Mar 09, 2017 4:06 pm    Post subject:
Reply with quote

Oh thanks Nic for pointing out that.
Sorry all.

PROV_ID is 12345 only and not 111(sorry, typo mistake)
I just want the first 2 row values to be in column fields and can ignore the third row value onwards.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Formatting multiple records to a sing... Vignesh Sid SYNCSORT 3 Tue Nov 07, 2017 12:22 pm
No new posts Updating multiple counts in trailer!! Vignesh Sid SYNCSORT 4 Mon Nov 06, 2017 1:04 pm
No new posts Selecting a row from multiple tables! Vignesh Sid DB2 2 Thu Oct 26, 2017 6:09 pm
No new posts Extend the decimal values in DIVISION Balaryan DFSORT/ICETOOL 3 Thu Oct 05, 2017 4:05 pm
No new posts display the sign only if the value is... useit DFSORT/ICETOOL 3 Wed Oct 04, 2017 5:53 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us