View previous topic :: View next topic
|
Author |
Message |
gylbharat
Active Member
Joined: 31 Jul 2009 Posts: 565 Location: Bangalore
|
|
|
|
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 |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
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 |
|
|
gylbharat
Active Member
Joined: 31 Jul 2009 Posts: 565 Location: Bangalore
|
|
|
|
Thanks GuyC.... It worked very well. |
|
Back to top |
|
|
|