• leesider (11/26/2012)


    Sean Lange (11/26/2012)


    You should look at datepart.

    For example, 2012-04-03 is in the fifteenth week of the year so if that date appears then the week number 15 should appear along side it.

    You sure about that? I believe it is in the 14th week.

    select DATEPART(ww, '2012-04-03')

    Possibly, doesn't really matter what the week number is as long as it is the correct one.

    OK so to borrow from Cadavre's post...

    SELECT [YEAR] = YEAR(startup_Time),

    DATEPART(ww, startup_Time) as WeekNumber,

    [MONTH_NUMBER] = DENSE_RANK() OVER(ORDER BY DATEADD(MONTH, DATEDIFF(MONTH, 0, startup_Time), 0)),

    startup_Time

    FROM #KWHtemp;

    _______________________________________________________________

    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/