• Ninja's_RGR'us (8/19/2011)


    ChrisM@Work (8/19/2011)


    Ninja's_RGR'us (8/19/2011)


    Quite easy with a calendar table.

    Select top 1 * FROM dbo.Calendar WHERE Y = 2011 AND DW = <whatever fits your setting> ORDER BY dt.

    Just as easy without. Make one for the first week of the year and pick the correct row from it 😉

    Too many good uses to not have 1.

    Since my table is less than 2 MB and that I can query the table with an <clustered>index I don't really see the point of trying to go much faster than that. Not saying it's impossible, just never had that need! 😉

    I agree with Remi on this one. There are just too many uses for calendar tables not to have them. When properly done they give better performance than complicated date math in most cases. You can spell out a month name any way you want in any language and have it displayed correctly. Very simple aggregating and grouping. All sorts of uses.

    Todd Fifield