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

Columns one after the other.


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Mon Aug 08, 2011 5:17 pm
Reply with quote

Hi,

I have a requirement where i have to select 2 columns of a table in the below order.

Code:


COL1    COL2
AAAA     1111
BBBB     1111
CCCC    1111
DDDD    1111

Output should be
Code:

AAAA
1111

BBBB
1111

CCCC
1111

DDDD
1111


There is a blank line also required after every set.

Please tell me how this can be achieved using SQL. I am using DB2 V8.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Mon Aug 08, 2011 5:29 pm
Reply with quote

it is a strange request for a SQL.
SQL is normally for data retrieval.
Formatting is normally done in a program or reporting tool.

but nevertheless: this gives you the desired result
Code:
select outp from (
select col1,1 as ord,col1 as outp from cte
union all
select col1,2 as ord,char(col2) as outp from cte
union all
select col1,3 as ord, '    ' as outp from cte
) X
order by col1, ord
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Mon Aug 08, 2011 6:40 pm
Reply with quote

Thanks GuyC.... It worked very well.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Remote Unload of CLOB Columns DB2 6
No new posts Increase the number of columns in the... IBM Tools 3
No new posts DB2 Views with Multiple SQL & Col... DB2 8
No new posts SORT - To repeat a string in same col... SYNCSORT 3
No new posts JCL - To repeat a string in same colu... JCL & VSAM 2
Search our Forums:

Back to Top