Help needed in data pivoting without aggregate in sqlserver 2008?

Select geo, prd, pack, sum(sales_22_1) sales_22_1, sum(sales_22_2) sales_22_2, sum(sales_23_1) sales_23_1, sum(sales_23_2) sales_23_2, sum(sales_24_1) sales_24_1, sum(sales_24_2) sales_24_2 from (select geo, prd, pack, (case when datatype = 22 then sales1 else null end) as sales_22_1, (case when datatype = 22 then sales2 else null end) as sales_22_2, (case when datatype = 23 then sales1 else null end) as sales_23_1, (case when datatype = 23 then sales2 else null end) as sales_23_2, (case when datatype = 24 then sales1 else null end) as sales_24_1, (case when datatype = 24 then sales2 else null end) as sales_24_2 from mytab) group by geo, prd, pack (untested, since I don't have a SQL server instance available).

Recent versions of SQL Server have a PIVOT function. Here is an example of how to do pivoting in several SQL Server versions. And there are many good answers to this very popular SO question: SQL Server PIVOT examples?

Here is an example from that page of what a simple PIVOT statement looks like: SELECT act AS 'Action', View as 'View', Edit as 'Edit' FROM ( SELECT act, cmd FROM data ) AS src PIVOT ( MAX(cmd) FOR cmd IN (View, Edit) ) AS pvt.

– tanvir80 Jun 8 at 10:04 Start with the inner SELECT. Make sure you're getting the right data. The outer SELECT specifies the new columns.

You'll probably have to start small and gradually build your SQL. – DOK Jun 8 at 11:06.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions