• r.mitchell (6/26/2013)


    I use a recursive CTE for this usually. In this example it will give you all the days in June. Had to use this when I created a calendar application with recurring entries. Sort of like outlook and needed to match the day of week based on its recurrence schedule. Like every week, 2 weeks, month... etc.

    DECLARE @StartDate DATE = '6/1/2013';

    WITH dt(MDate) AS (

    SELECT @StartDate AS MDate

    UNION ALL

    SELECT DATEADD(dd, 1, MDate)

    FROM dt

    WHERE DATEADD(dd, 1, MDate) < DATEADD(mm, 1, @StartDate)

    )

    SELECT MDate FROM dt

    Please, avoid this and read the following article:

    Hidden RBAR: Counting with Recursive CTE's[/url]

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2