I have been searching around for an example on how to group the count of date intervals that are exclusive.One way it can be done is this way:DECLARE @tmp TABLE(cnt INT)INSERT INTO @tmp(cnt)SELECT COUNT(*) AS ProblemCntFROM ProblemsWHERE Closed IS NULLAND (DATEDIFF(DAY, Opened, GETDATE()) <=10)INSERT INTO @tmp(cnt)SELECT COUNT(*) AS ProblemCntFROM ProblemsWHERE Closed IS NULLAND (DATEDIFF(DAY, Opened, GETDATE()) >10 AND DATEDIFF(DAY, Opened, GETDATE()) <=20) INSERT INTO @tmp(cnt)SELECT COUNT(*) AS ProblemCntFROM ProblemsWHERE Closed IS NULLAND (DATEDIFF(DAY, Opened, GETDATE()) >20 AND DATEDIFF(DAY, Opened, GETDATE()) <=30) SELECT cnt FROM @tmp
Problem is with the way it's done above is it is not as dynamic as needed and it is needed to go up to 300 days.So, there would be a lot of selects and inserts. Not very proficient.Also, I have been looking at something like this:dateadd(day, 5 + (datediff(day, 0, Opened) / 5) * 5, 0)
This is just a sample of a possibility that needs adjustment.Does anyone have a better suggestion on how to achieve this without using the temp table above?Thanks...