Posts

Showing posts from July, 2022

Creating a date dimension or calendar table in SQL Server

Image
  Creating a date dimension or calendar table in SQL Server By:  Aaron Bertrand    |   Updated: 2020-04-06   |    Comments (83)    |   Related:  1  |  2  |  3  |  4  |  5  |  More  >  Dates Problem A calendar table can be immensely useful, particularly for reporting purposes, and for determining things like business days between two dates. I often see people struggling with manually populating a calendar or date dimension table; usually there are lots of loops and iterative code constructs being used. In this tip I will show you how to build and use a calendar table using a set-based solution that is powerful and easily customizable. Solution I build calendar tables all the time, for a variety of business applications, and have come up with a few ways to handle certain details. Sharing them here will hopefully prevent you from re-inventing any wheels when populating your own tables. One of the biggest objections I hear to calendar tables is that people don't want to create a tab