WITH cte AS
(
SELECT ID_Dipendente, ID_Timesheet, SUM(Ore) AS Ore
FROM Timesheet
GROUP BY ID_Dipendente, ID_Timesheet
)
SELECT ID_Dipendente,
CASE WHEN ISNULL([01/2009], 0) < 160 THEN '-' ELSE 'Completo' END AS [Gennaio],
CASE WHEN ISNULL([02/2009], 0) < 160 THEN '-' ELSE 'Completo' END AS [Febbraio],
CASE WHEN ISNULL([03/2009], 0) < 160 THEN '-' ELSE 'Completo' END AS [Marzo],
CASE WHEN ISNULL([04/2009], 0) < 160 THEN '-' ELSE 'Completo' END AS [Aprile],
CASE WHEN ISNULL([05/2009], 0) < 160 THEN '-' ELSE 'Completo' END AS [Maggio],
CASE WHEN ISNULL([06/2009], 0) < 160 THEN '-' ELSE 'Completo' END AS [Giugno],
CASE WHEN ISNULL([07/2009], 0) < 160 THEN '-' ELSE 'Completo' END AS [Luglio],
CASE WHEN ISNULL([08/2009], 0) < 160 THEN '-' ELSE 'Completo' END AS [Agosto],
CASE WHEN ISNULL([09/2009], 0) < 160 THEN '-' ELSE 'Completo' END AS [Settembre],
CASE WHEN ISNULL([10/2009], 0) < 160 THEN '-' ELSE 'Completo' END AS [Ottobre],
CASE WHEN ISNULL([11/2009], 0) < 160 THEN '-' ELSE 'Completo' END AS [Novembre],
CASE WHEN ISNULL([12/2009], 0) < 160 THEN '-' ELSE 'Completo' END AS [Dicembre]
FROM cte
PIVOT (SUM(Ore) FOR ID_Timesheet IN ( [01/2009], [02/2009], [03/2009], [04/2009], [05/2009], [06/2009],
[07/2009], [08/2009], [09/2009], [10/2009], [11/2009], [12/2009])) AS pvt