It's easy to trim the time to the last 15 minutes (for example) by doing something like:
SELECT dateadd(minute, datediff(minute, '20000101', yourDateTimeField) / 15 * 15, '20000101') AS the15minuteBlock, COUNT(*) as Cnt FROM yourTable GROUP BY dateadd(minute, datediff(minute, '20000101', yourDateTimeField) / 15 * 15, '20000101');
Use similar truncation methods to group by hour, week, etc.
You can always wrap it in a CASE statement to process several methods using:
GROUP BY CASE @option WHEN 'week' THEN dateadd(week, .....
Rob farley
source share