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 row to the column

Author  Topic 

mtvaran
Starting Member

1 Post

Posted - 2010-11-12 : 23:58:54
Hi guys, i have a big problem of creating row as a column.
Ex:

id | name
1 | A
2 | B
3 | C

i want to change as this...

A | B | C
1 | 2 | 3

i know for you guys, this is not a big issue! could anyone please help me?
thank you

chadmat
The Chadinator

1974 Posts

Posted - 2010-11-14 : 03:06:39
Look up Pivot in Books Online

-Chad
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2010-11-15 : 05:12:12
or try like this too
select max(case when name = 'A' then id end) as 'A',
max(case when name = 'B' then id end) as 'B',
max(case when name = 'C' then id end) as 'C'
from table name
Go to Top of Page
   

- Advertisement -