SQL Server Forums
Profile | Register | 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
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masterdineen
Aged Yak Warrior

United Kingdom
548 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
52317 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  
 New 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.03 seconds. Powered By: Snitz Forums 2000