selectSUM(CASE WHEN DATEPART(MONTH, scheddate) = DATEPART(MONTH, GetDate()) THEN qty ELSE 0 END) AS month_current,SUM(CASE WHEN left(convert(varchar, scheddate, 112), 6) = left(convert(varchar, dateadd(month, 1, GetDate()), 112), 6) THEN qty ELSE 0 END) AS month_2,SUM(CASE WHEN left(convert(varchar, scheddate, 112), 6) = left(convert(varchar, dateadd(month, 2, GetDate()), 112), 6) THEN qty ELSE 0 END) AS month_3,SUM(CASE WHEN left(convert(varchar, scheddate, 112), 6) = left(convert(varchar, dateadd(month, 3, GetDate()), 112), 6) THEN qty ELSE 0 END) AS month_4,SUM(CASE WHEN left(convert(varchar, scheddate, 112), 6) = left(convert(varchar, dateadd(month, 4, GetDate()), 112), 6) THEN qty ELSE 0 END) AS month_5,SUM(CASE WHEN left(convert(varchar, scheddate, 112), 6) = left(convert(varchar, dateadd(month, 5, GetDate()), 112), 6) THEN qty ELSE 0 END) AS month_6,SUM(CASE WHEN left(convert(varchar, scheddate, 112), 6) = left(convert(varchar, dateadd(month, 6, GetDate()), 112), 6) THEN qty ELSE 0 END) AS month_7,SUM(CASE WHEN left(convert(varchar, scheddate, 112), 6) = left(convert(varchar, dateadd(month, 7, GetDate()), 112), 6) THEN qty ELSE 0 END) AS month_8,SUM(CASE WHEN left(convert(varchar, scheddate, 112), 6) = left(convert(varchar, dateadd(month, 8, GetDate()), 112), 6) THEN qty ELSE 0 END) AS month_9,SUM(CASE WHEN left(convert(varchar, scheddate, 112), 6) = left(convert(varchar, dateadd(month, 9, GetDate()), 112), 6) THEN qty ELSE 0 END) AS month_10,SUM(CASE WHEN left(convert(varchar, scheddate, 112), 6) = left(convert(varchar, dateadd(month, 10, GetDate()), 112), 6) THEN qty ELSE 0 END) AS month_11,SUM(CASE WHEN left(convert(varchar, scheddate, 112), 6) = left(convert(varchar, dateadd(month, 11, GetDate()), 112), 6) THEN qty ELSE 0 END) AS month_12from (select getdate() as scheddate, 1 as qtyunion allselect '20090605' as scheddate, 1 as qtyunion allselect '20090605' as scheddate, 1 as qtyunion allselect '20091105' as scheddate, 1 as qtyunion allselect '20100205' as scheddate, 1 as qty) T1