• Suggest that master dates table is best.

    But if it's not available, here's a query that will give you the dates for a given year and month.

    Still working on how to get the cross-tab/pivot/matrix working to have these in columns, but this is a start:

    with daylist as

    (

    select 1 as daynum

    union all

    select dl.daynum + 1 as daynum

    from daylist dl

    where dl.daynum + 1 <=

    day( DATEADD( s, -1, DATEADD( mm, DATEDIFF( m, 0,

    CAST(@yearnum + '-' + @monthnum + '-01' AS datetime))+1,0)))

    )

    select daynum from daylist order by daynum;