IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

DB2 query Using Recursion, Converting Rows to Column


IBM Mainframe Forums -> DB2
Post new topic   This topic is locked: you cannot edit posts or make replies.
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
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: 2455
Location: Hampshire, UK

PostPosted: Tue Jan 03, 2017 4:19 pm
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
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: 2455
Location: Hampshire, UK

PostPosted: Wed Feb 15, 2017 1:31 pm
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. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts To get the count of rows for every 1 ... DB2 3
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top