SQL Server Common Table Expression – Creating a Calendar

SQL Server Common Table Expression – Creating a Calendar

Friends,

In this post I am going to discuss, how to retrieve a month’s calendar by passing month and year as parameters to the script or procedure. The important point to note here is that if we use SQL Server Common Table Expression there is no need to create temporary table or table variable to store and then iterate over the days and dates of the month.

Before we proceed to our proc, copy the two functions below and run them in SSMS.

Share This Story, Choose Your Platform!

MSBI Developer having 4 years of experience in Report Writing using SSRS. Writing ETL packages for both OLTP and DW databases Using SSIS with focus on package optimization.
In free time I love to explore new stuff on SQL Server. Love Bicycling and Swimming. Die Hard Fan of Heavy Metal Music.