Date ranges in T/SQL

前端 未结 4 950
北荒
北荒 2021-01-15 06:44

For a current project I am working I need to return an aggregate report based on date ranges.

I have 3 types of reports, yearly, monthly and daily.

To assis

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-15 07:19

    If you prefer a set-based solution, use a tactic like the one shown in the following link to produce a range of numeric values from x to y. Then, just join to it with DATEADD() and your own custom limits to create ranges of days, months, quarters, years, or whatever else. I find it helpful to have this range query as a view.

    Generate Ranges In SQL

提交回复
热议问题