Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

DB2 query Using Recursion, Converting Rows to Column

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
smilewithashu2

New User


Joined: 28 Dec 2016
Posts: 1
Location: India

PostPosted: Tue Jan 03, 2017 12:50 pm    Post subject: DB2 query Using Recursion, Converting Rows to Column
Reply with quote

I am looking for the query in which I need to convert rows to columns using Db2 recursion:


Input and Output is the attached, I am not looking for the query using CASE as in which case the columns has many values.


Any replies will be appreciated.

Thanks
Back to top
View user's profile Send private message

Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1825
Location: UK

PostPosted: Tue Jan 03, 2017 4:19 pm    Post subject:
Reply with quote

Please do not use attachments - a simple cut and paste (using the code tags) is sufficient and more efficient.

There is the same topic just a few below yours. was that not sufficient for you?

And there appears to be a sudden 'requirement' for this type of processing due to a competition. as it is a compettion then getting the answer from a forum is cheating. However, you should research CTEs (Common Table Expressions).
Back to top
View user's profile Send private message
Delip

New User


Joined: 13 Sep 2007
Posts: 46
Location: Bangalore

PostPosted: Wed Feb 15, 2017 12:37 pm    Post subject:
Reply with quote

Hi,

Can't we use Union all like below,

(select HR NAME, 'HR' DEPARTMENT FROM TABLE WHERE HR > ' ')

UNION
(select FINANCE NAME, 'FINANCE' DEPARTMENT FROM TABLE WHERE FINANCE > ' ')

UNION
.
.
.

Regards,
Dileep
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1825
Location: UK

PostPosted: Wed Feb 15, 2017 1:31 pm    Post subject:
Reply with quote

Quote:
Can't we use Union all like below

possibly; but the requirement, for the competition, is to use recursion.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies.    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 Loading data to table gives wrong for... Raghu navaikulam DB2 18 Thu Jul 13, 2017 2:11 pm
No new posts compare 2 rows within the same file ram_vizag SYNCSORT 7 Wed Jun 14, 2017 12:34 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us