Create a table variable of dates within a range

Whether to iterate through them, or join to the table, sometimes a table containing nothing but dates within a specific range comes in handy. Here’s my code snippet for creating such a table:

 

This will yield a table of these values (thru the @endDate):

 

This can also be modified to dateadd() by month, week, etc.. or use a dynamic date range by changing the @startDate and @endDate to calculated dates instead of static values.

Share on Facebook