• DECLARE@start_date DATE, @end_date DATE

    SELECT@start_date = '20130103', @end_date = '20130123'

    SELECTDATEPART(WEEK,Dates.Dt) AS week_nbr, MIN(Dates.Dt) AS start_date, MAX(Dates.Dt) AS end_date

    FROM(

    SELECTDATEADD(DAY,sv.number,@start_date) AS Dt

    FROMmaster.dbo.spt_values AS sv -- You can use TALLY table instead of this

    WHEREsv.type = 'P' AND sv.number <= DATEDIFF(DAY,@start_date,@end_date)

    ) AS Dates

    GROUP BY DATEPART(WEEK,Dates.Dt)

    You can find the script to generate a TALLY table below

    http://www.sqlservercentral.com/scripts/Advanced+SQL/62486/


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/