• And here is an example of doing this without using a recursive cte for counting. This code also will only return data for the specified month even if the @StartDate is not the first of the month. To see what I mean change the start date to June 2nd and run the recursive version. It will return dates in July because it assumes the start date is the first of the month. Now run the one below with the same start date and it will only return 28 rows now.

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

    WITH

    E1(N) AS (select 1 from (values (1),(1),(1),(1),(1),(1),(1),(1),(1),(1))dt(n)),

    E2(N) AS (SELECT 1 FROM E1 a, E1 b), --10E+2 or 100 rows

    cteTally(N) AS

    (

    SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) FROM E2

    )

    select DATEADD(day, N - 1, @StartDate)

    from cteTally

    where N <= DATEDIFF(day, @StartDate, dateadd(month, datediff(month, 0, @StartDate) + 1, 0))

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/