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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 transpose the table

Author  Topic 

moseph
Starting Member

8 Posts

Posted - 2010-06-07 : 21:40:54
Hi, i am new to pivoting and transposing tables so here goes:

I have a table with 2 columns :

column_header | column_value
Available | yes
Type | used
Maintained By | Drax.Inc

I want this in this form:
Available | Type | Maintained By
yes | used | Drax.Inc

any suggestions

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2010-06-08 : 05:58:08
Look up PIVOT, there are loads of examples strewn over the interweb.
Go to Top of Page

moseph
Starting Member

8 Posts

Posted - 2010-06-08 : 11:41:48
quote:
Originally posted by RickD

Look up PIVOT, there are loads of examples strewn over the interweb.



they all use the darn aggregate function, i dont have any numerical columns in my example.
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-06-08 : 11:48:08
Something like this
select max(case when column_header = 'Available' then column_value else null end) as [Available]
,max(case when column_header = 'Type' then column_value else null end) as [Type]
,max(case when column_header = 'Maintained By' then column_value else null end) as [Maintained By]
from tableA
Go to Top of Page

moseph
Starting Member

8 Posts

Posted - 2010-06-08 : 11:54:47
quote:
Originally posted by vijayisonly

Something like this
select max(case when column_header = 'Available' then column_value else null end) as [Available]
,max(case when column_header = 'Type' then column_value else null end) as [Type]
,max(case when column_header = 'Maintained By' then column_value else null end) as [Maintained By]
from tableA




is there a way where its not hard coded?
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-06-08 : 12:21:50
Search for Dynamic Cross Tab here.
Go to Top of Page

moseph
Starting Member

8 Posts

Posted - 2010-06-08 : 13:19:48
quote:
Originally posted by vijayisonly

Search for Dynamic Cross Tab here.



all the examples use the aggregate functions, is there NO example without the aggregate functions??
Go to Top of Page

moseph
Starting Member

8 Posts

Posted - 2010-06-08 : 13:30:17
ok figured it out, thnx for the help
Go to Top of Page
   

- Advertisement -