• Very interesting technique.

    But inserting extra data and then deleting them is not the best solution, because delete operations are expensive. It's better to add a condition in order to insert only necessary data:

    INSERT INTO #Dates

    (

    [Date],

    [SomeValueForDate]

    )

    SELECT DATEADD(DAY, @n, [Date]) AS [Date],

    @n AS [SomeValueForDate]

    FROM #Dates

    WHERE DATEADD(DAY, @n, [Date]) <= @dtTo -- No need to delete data after that