• A lot of people set up a Calendar table specifically for this kind of thing -

    see http://www.sqlservercentral.com/scripts/Date/68389/ for example.

    Using this as a base, I came up with this:

    DECLARE @StartDate Date,

    @EndDate Date,

    @WeekStart TinyInt;

    SELECT @StartDate = '03 Jan 2013',

    @EndDate = '23 Jan 2013',

    @WeekStart = 1;

    WITH cte_date_base_table AS

    (

    SELECT

    @StartDate AS calendar_date

    UNION ALL

    SELECT

    DATEADD (DAY, 1, CTE.calendar_date)

    FROM

    cte_date_base_table CTE

    WHERE

    DATEADD (DAY, 1, CTE.calendar_date) <= @EndDate

    )

    , cte2 AS

    (

    SELECT calendar_date,

    DATEPART(dw, calendar_date) AS dow,

    DATEPART(week, calendar_date) AS week_nbr

    FROM cte_date_base_table

    )

    SELECT week_nbr,

    MIN(calendar_date) as start_date,

    MAX(calendar_date) as end_date

    FROM cte2

    GROUP BY week_nbr