Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Convert columns to rows

Author  Topic 

goodman2253
Yak Posting Veteran

88 Posts

Posted - 2012-04-21 : 09:14:35
Hi All
I have a table name T1 which looks like

X1--Y1
A---B
C---D
E---F
G---H
I---J

I want the write the select query which gives the output like
A
B
C
D
E
F
G
H
I
J

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-04-21 : 10:11:35
SELECT X1 FROM T1
UNION ALL
SELECT Y1 FROM T1
Go to Top of Page

goodman2253
Yak Posting Veteran

88 Posts

Posted - 2012-04-21 : 10:17:44
But it is giving the output as
a
c
e
g
b
d
f
h
But i want the output as
A
B
C
D
E
F
G
H
I
J
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-04-21 : 10:33:37
SELECT X1 FROM T1
UNION ALL
SELECT Y1 FROM T1
ORDER BY X1
Go to Top of Page
   

- Advertisement -