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.
Hi All,I need to do unpivoting operation for below resultsNov09--Dec09----Jan1014-----29-------78and want in formatMonth----CountNov09----14Dec09----29Jan10----78T.I.A
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts
Posted - 2011-10-31 : 08:57:11
select [month] = 'Nov09', [Count] = nov09 from tblunion allselect 'Dec09', Dec09 from tblunion allselect 'Jan10', Jan10 from tbl==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy.
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2011-10-31 : 11:28:21
using unpivot
declare @tbl table(Nov09 int,Dec09 int,Jan10 int)insert @tblselect 14,29,78select [Month],valfrom @tblunpivot(val for [Month] in (Nov09,Dec09,Jan10))uoutput-----------------------------------Month val-----------------------------------Nov09 14Dec09 29Jan10 78
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/