SQL Server Pivot or UnPivot so confused -
i working on creating report using sql server database. unfortunately not able figure out how it. here database structure: create table #mytable ( [foryear] [smallint] not null, [formonth] [tinyint] not null, [trainingdonethismonth] [bit] null, [foodqualitystatus] [bit] null, [noofalldrugtests] [int] null, [noofallalcoholtests] [int] null ) insert #mytable values (2016, 1, 1, 0, 5, 10), (2016, 2, 0, 1, 15, 5), (2016, 3, 1, 0, 20, 15), (2016, 4, 0, 1, 5, 25), (2016, 5, 1, 0, 10, 30) i need report in following format. column names converted rows , corresponding values transformed. report sample i have tried pivot , unpivot not able desired results please help. this trying: select 1,2,3 ( select noofallalcoholtests,formonth #mytable ) d pivot ( sum(noofallalcoholtests) formonth in ([1],[2],[3]) ) piv; unpivot pivot: select objective, [january], [february], [march], [april], ...