How do you generate the sequence of dates from one date to other?

This is possible through Recursive CTEs.

You can execute the below code logic by passing @Start and @End variable values.
DECLARE @Start datetime = ’02/08/2016′

DECLARE @End datetime = ’02/13/2016′

;WITH Auto_Date AS (

    SELECT @Start AS Dates_List


    SELECT DATEADD(d,01,Dates_List)

       FROM Auto_Date

       WHERE Dates_List < @End


SELECT * FROM Auto_Date;

The above code snippet creates a CTE called ‘Auto_Date’ and calls itself to increment dates by 1 from the Start date to the End date we provided.


Sequence of Dates

Happy Reading  :-) 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.