This will do it:--Creating TableCreate Table Ex(Project varchar(30), pass int, month varchar(30) )--Inserting Sample DataInsert Into ExSelect 'WSBS-AR', 85, 'MAR-12'Union ALLSelect 'WSBS-Interface', 74, 'MAR-12'Union ALLSelect 'WSBS-Payments', 88, 'MAR-12'Union ALLSelect 'WSBS-AR', 92, 'FEB-12'Union ALLSelect 'WSBS-Interface', 85, 'FEB-12'Union ALLSelect 'WSBS-Payments', 65, 'FEB-12'Union ALLSelect 'WSBS-AR', 45, 'DEC-11'Union ALLSelect 'WSBS-Interface', 25, 'DEC-11'Union ALLSelect 'WSBS-Payments', 65, 'DEC-11'--Query for your requirement;With CTEAs(Select Project,(Case When month = 'MAR-12' Then SUM(pass) Else NULL End) As MAR_12,(Case When month = 'FEB-12' Then SUM(pass) Else NULL End) As FEB_12,(Case When month = 'DEC-11' Then SUM(pass) Else NULL End) As DEC_11From ExGroup By Project, month)Select a.Project, a.MAR_12, b.FEB_12, c.DEC_11 From CTE As aJOIN CTE as b ON a.Project = b.ProjectJOIN CTE as c ON a.Project = c.ProjectWhere a.MAR_12 IS NOT NULL AND b.FEB_12 IS NOT NULL AND c.DEC_11 IS NOT NULL
N 28° 33' 11.93148"E 77° 14' 33.66384"