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
 
Columns one after the other.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Columns one after the other.
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    Post subject:
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    Post subject:
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    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 unload data from table with lob columns farhad_evan DB2 1 Sat Apr 22, 2017 1:32 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am
No new posts Combine columns without breaking words Indrajit_57 SYNCSORT 1 Sat Mar 19, 2016 9:33 am
No new posts 3 columns update Seppe DB2 2 Mon Jun 22, 2015 6:43 pm

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