Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Does anyone know if it is possible to pivot this table. I need year as column names and the other 3 columns as rows.I have tried about 20 different ways over 3 days and keep getting no where.ID YearN EI Booked Rooms1 2008 990000.00 3 02 2009 7007257.50 44 03 2010 5956687.50 61 3804 2011 1009972.00 35 205 2012 886590.00 27 106 2013 524737.00 3 07 2014 224250.00 2 0
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2012-04-10 : 16:22:00
you can it would be something like
SELECT *FROM (SELECT YearN,Category,Value FROM table t UNPIVOT (Value FOR Category IN ([EI],[Booked],[Rooms]))c)mPIVOT (MAX(Value) FOR YearN IN ([2008],[2009],[2010],[2011],...))p
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
ecsmoore
Starting Member
5 Posts
Posted - 2012-04-11 : 16:31:37
Thank you so much. This worked like a charm.So many people looking for this....
quote:Originally posted by visakh16 you can it would be something like
SELECT *FROM (SELECT YearN,Category,Value FROM table t UNPIVOT (Value FOR Category IN ([EI],[Booked],[Rooms]))c)mPIVOT (MAX(Value) FOR YearN IN ([2008],[2009],[2010],[2011],...))p
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2012-04-12 : 01:06:11
wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/