Recently a developer came to me seeking my help in generate list dates between date range for a report.  Being a .Net developer he said that one solution he had is to do row by row processing either by using while loop or a cursor. We exchanged smiles and he understood what I had in my mind..

I came up with 2 solutions for this problem. One is to use a tally table and another one using a recursive CTE.

Method 1: 

Method 2:

Method 1 performs a bit better than method 2 for large result set.

Do let me know if you have a different way to do this.



Ahmad Osama

Like us on FaceBook Follow us on Twitter | Join the fastest growing SQL Server group on FaceBook

Follow me on TwitterFollow me on FaceBook