i have a query in which i am getting result like this and i am geting the result set in below. But i need to get as shown in last one DatePeriod Good Fair Poor NotCategorised NotTested GoodPercentage FairPercentage PoorPercentage NotCategorisedPercentage NotTestedPercentageFeb 2013 4 0 0 0 60 6.25 0 0 0 93.75
And for this one i have written query using UNPIVOT Select DatePeriod,Legend FROM (select DatePeriod,Good,Fair,Poor,NotCategorised,NotTested,GoodPercentage,FairPercentage,poorPercentage,NotCategorisedPercentage,NotTestedPercentage from #cte )PUNPIVOT(Legend FOR #CTE IN (Good,Fair,Poor,NotCategorised,NotTested))AS UNPVT;
and i am not getting required output my result set need to be like this year Legend percent countDec-12 Good 13.89 35Dec-12 Fair 0 0Dec-12 Poor 0 0Dec-12 NC 0 0Dec-12 NoData 86.11 217
Suggest me