Código SQL:
Ver originalCREATE TABLE #temp
(
tipocanal VARCHAR(20),
periodo VARCHAR(10),
vol INT
)
INSERT INTO #temp VALUES ('Super','Ago',7)
INSERT INTO #temp VALUES ('Hiper','Ago',12)
INSERT INTO #temp VALUES ('Mercal','Ago',25)
INSERT INTO #temp VALUES ('Super','Sep',15)
INSERT INTO #temp VALUES ('Hiper','Sep',32)
INSERT INTO #temp VALUES ('Mercal','Sep',18)
INSERT INTO #temp VALUES ('Super','Oct',41)
INSERT INTO #temp VALUES ('Hiper','Oct',20)
INSERT INTO #temp VALUES ('Mercal','Oct',7)
INSERT INTO #temp VALUES ('Super','Nov',15)
INSERT INTO #temp VALUES ('Hiper','Nov',21)
INSERT INTO #temp VALUES ('Mercal','Nov',9)
SELECT tipocanal,SUM(isnull(bimestre1,0)) Bimestre1 ,SUM(isnull(bimestre2,0)) Bimestre2,SUM(isnull(bimestre3,0)) Bimestre3,
SUM(isnull(bimestre4,0)) Bimestre4,SUM(isnull(bimestre5,0))Bimestre5,SUM(isnull(bimestre6,0))Bimestre6
FROM
(
SELECT
tipocanal,
CASE WHEN periodo='Ene' OR periodo='Feb' THEN SUM(vol) END AS Bimestre1,
CASE WHEN periodo='Mar' OR periodo='Abr' THEN SUM(vol) END AS Bimestre2,
CASE WHEN periodo='May' OR periodo='Jun' THEN SUM(vol) END AS Bimestre3,
CASE WHEN periodo='Jul' OR periodo='Ago' THEN SUM(vol) END AS Bimestre4,
CASE WHEN periodo='Sep' OR periodo='Oct' THEN SUM(vol) END AS Bimestre5,
CASE WHEN periodo='Nov' OR periodo='Dic' THEN SUM(vol) END AS Bimestre6
FROM #temp
GROUP BY tipocanal,periodo
) t1 GROUP BY tipocanal
Resultado:
tipocanal Bimestre1 Bimestre2 Bimestre3 Bimestre4 Bimestre5 Bimestre6
Hiper 0 0 0 12 52 21
Mercal 0 0 0 25 25 9
Super 0 0 0 7 56 15
Si me pudieras ayudar con minimo un gracias mucho te lo agradeceria :)