DROP TABLE #ContactRoutingDetailGOCREATE TABLE #ContactRoutingDetail (queueTime INT, StartDateTime DATETIME)GOINSERT INTO #ContactRoutingDetail (queueTime, StartDateTime)SELECT 10, '2008-01-31 11:23:32.937' UNION ALL -- THUSELECT 10, '2008-01-31 11:22:32.937' UNION ALLSELECT 10, '2008-01-30 11:21:32.937' UNION ALL -- WEDSELECT 10, '2008-01-30 11:19:32.937' UNION ALLSELECT 10, '2008-01-29 11:18:32.937' UNION ALL -- TUESELECT 10, '2008-01-29 11:17:32.937' UNION ALLSELECT 10, '2008-01-28 11:16:32.937' UNION ALL -- MONSELECT 10, '2008-01-28 11:15:32.937' UNION ALLSELECT 10, '2008-01-27 11:14:32.937' UNION ALL -- SUNSELECT 10, '2008-01-27 11:13:32.937' UNION ALLSELECT 10, '2008-01-27 00:00:00.000' UNION ALLSELECT 10, '2008-01-26 23:59:59.997' UNION ALL -- SATSELECT 10, '2008-01-26 11:11:32.937' UNION ALLSELECT 10, '2008-01-26 00:00:00.000' UNION ALLSELECT 10, '2008-01-25 11:10:32.937' UNION ALL -- FRISELECT 10, '2008-01-25 11:09:32.937' UNION ALLSELECT 10, '2008-01-24 11:08:32.937' UNION ALL -- THUSELECT 10, '2008-01-24 11:07:32.937' UNION ALLSELECT 10, '2008-01-23 11:06:32.937' UNION ALL -- WEDSELECT 10, '2008-01-23 11:05:32.937' UNION ALLSELECT 10, '2008-01-22 11:04:32.937' UNION ALL -- TUESELECT 10, '2008-01-22 11:03:32.937' UNION ALLSELECT 10, '2008-01-21 11:02:32.937' UNION ALL -- MONSELECT 10, '2008-01-21 11:01:32.937' UNION ALLSELECT 10, '2008-01-21 00:00:00.000' UNION ALLSELECT 10, '2008-01-20 23:59:59.997' UNION ALL -- SUNSELECT 10, '2008-01-20 11:59:32.937' UNION ALLSELECT 10, '2008-01-20 00:00:00.000' GODECLARE @Today DATETIMESET @Today = GETDATE() + 2 -- choose your run day / date for testingSET DATEFIRST 1 -- monday is now considered the first day of the week (check the current setting)SELECT SumDayTime, CONVERT(DATETIME, TextDate) AS StartDateTime FROM ( SELECT SUM(queueTime) AS SumDayTime, CONVERT(CHAR(8), StartDateTime, 112) AS TextDate, DATENAME(dw,StartDateTime) AS DayName, DATEPART(dw, StartDateTime) AS DayNo FROM #ContactRoutingDetail WHERE StartDateTime >= CONVERT(CHAR(8), @Today - (DATEPART(dw, @Today)+6), 112) AND StartDateTime < CONVERT(CHAR(8), @Today - (DATEPART(dw, @Today)+0), 112) GROUP BY CONVERT(CHAR(8), StartDateTime, 112), DATENAME(dw,StartDateTime), DATEPART(dw, StartDateTime)) tORDER BY t.TextDate