|
Question : DateTime Group By question
|
|
I am writing a report and the users and they would like to select the grouping of the report.
All the grouping will be on a single datetime field (oddly enough named datetime).
They would like to be able to choose if the report is grouped by half hour, day, week, or month.
I can accomplish day by using: GROUP BY CONVERT(VARCHAR(10),DateTime, 110)
But how can I accomplish half hour, week, or month?
Many thanks for the help.
|
|
Answer : DateTime Group By question
|
|
Group By DatePart(Week, [Datetime])
Group By DatePart(Month, [Datetime])
Group by Year([DateTime]), Month([DateTime]), Day([DateTime]), DatePart(Minute, [DateTime])/30
|
|
|
|