• I might be wrong and probably shouldn't give a solution with such few information. If you could provide DDL and sample data, I could test it.

    This should work if your first day of the week is set to sunday and you need the counts from monday to sunday.

    Notice that I changed the variable data type to avoid the explicit conversions.

    Declare @CurrentDate DATETIME;

    SET @CurrentDate='2012-07-25';

    BEGIN

    WITH DateList AS

    (

    SELECTDATEADD(dd, 9 - DATEPART( dw, @CurrentDate), @CurrentDate) AS CreateDateTime,

    DATEADD(dd, 16 - DATEPART( dw, @CurrentDate), @CurrentDate) AS CreateDateTime2,

    1 AS Cnter

    UNION ALL

    SELECTDATEADD(WEEK, -1, CreateDateTime),

    DATEADD(WEEK, -1, CreateDateTime2),

    DateList.Cnter + 1

    FROM DateList

    WHERE DateList.Cnter < 5

    )

    SELECTdl.CreateDateTime AS ShipWeek,

    COUNT( sd.ID) AS TotalCount

    FROMDateList dl

    LEFT JOIN ShipmentDetail sdON sd.CreatedDateTime >= dl.CreateDateTime

    AND sd.CreatedDateTime < dl.CreateDateTime2

    GROUP BY dl.CreateDateTime

    END

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2