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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 pivoting with lots of column headings
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masterdineen
Aged Yak Warrior

United Kingdom
550 Posts

Posted - 01/29/2013 :  12:38:28  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 01/29/2013 :  13:05:29  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000