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 2008 Forums
 Transact-SQL (2008)
 pivoting with lots of column headings

Author  Topic 

masterdineen
Aged Yak Warrior

550 Posts

Posted - 2013-01-29 : 12:38:28
Hello there

i want to create a pivot for a metrics table.

but i have lots of headings, is there a way i can do the following if possible.
Below is an example of what i have at the moment.

select client_ref,
[15],[766],[771],[772],[773],[774],[775],[776] lots lots more


from(

select tickets.client_ref , tickets.occasionid, tickets.transactionid
from Ticket_Facts tickets) as query

pivot(

Count(transactionid) for occasionid
in ([15],[766],[771],[772],[773],[774],[775],[776],[777],[778])) as piv


is there a way i could do the following


select client_ref,
(select ref from [view]) as client_ref from(

select tickets.client_ref , tickets.occasionid, tickets.transactionid
from Ticket_Facts tickets) as query

pivot(

Count(transactionid) for occasionid
in (select ref from [view])) as piv


just want to cut down all the listing.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-29 : 13:05:29
see

http://beyondrelational.com/modules/2/blogs/70/posts/10840/dynamic-pivot-in-sql-server-2005.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -