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
 pivot table in sql 2005

Author  Topic 

cedlin
Starting Member

7 Posts

Posted - 2009-12-15 : 00:15:36
I would really appreciate a help... it is pivot table questions with dynamic number of colums but I could not find a good answer anywhere.

I got the following table with, say, too columns:
Col1 Col2
Cona rel1
Conb rel1
conb rel2
conc rel2
conb rel3
cona rel3

I want to get:
Col1 Col2 Col3 Col4
cona rel1 rel3
conb rel1 rel2 rel3
conc rel2

I guess I need to count over the number of 'rel's per 'con' and use the max of it but how?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-15 : 01:38:42
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

cedlin
Starting Member

7 Posts

Posted - 2009-12-24 : 09:06:20
Thank you, Madhivanan. The link was very helpful.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-24 : 09:14:14
quote:
Originally posted by cedlin

Thank you, Madhivanan. The link was very helpful.


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -