• Jason-299789 (1/8/2013)


    Final Edit,

    Dwain, I figured out why yours didnt work you're addind on the Julian day which is 1-365/366

    I think you need to add the Week day number something like this

    CREATE TABLE #Calendar

    ([Date] DATETIME PRIMARY KEY

    ,[Year] INT

    ,[JulWk] INT

    ,[WkDNo] INT

    ,ISO_WK AS (CAST([Year] AS CHAR(4)) + 'W' +

    CAST([JulWk] AS VARCHAR(2)) + '-' +

    CAST([WkDNo] AS VARCHAR(3)))

    )

    INSERT INTO #Calendar

    SELECT [Date], [Year], [JulWk], [WkDNo]

    FROM GenerateCalendar('20120101', 365*2)

    SELECT * FROM #Calendar

    WHERE ISO_WK LIKE '2012W26-[67]'

    Ah-ha! Indeed that does seem to fix it. Thought Joe meant Julian day not week day number.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St