• the fix is to group the data by day to get daily totals when more than one shipement exists per day, then get the max per week or month, depending on which total you wanted.

    ;WITH MyCTE([Invtid],[Case_ship],[Trandate],[FiscYr],[PerPost],[week_period],[day_period])

    AS

    (

    SELECT 'A',CONVERT(int,'10'),convert(date,' 1/1/2014'),'2014',' 1',' 1',' 1' UNION ALL

    SELECT 'A','3',' 1/1/2014','2014',' 1',' 1',' 1' UNION ALL

    SELECT 'A','50',' 1/2/2014','2014',' 1',' 1',' 2' UNION ALL

    SELECT 'A','30',' 1/3/2014','2014',' 1',' 1',' 3' UNION ALL

    SELECT 'A','20',' 1/9/2014','2014',' 1',' 2',' 2' UNION ALL

    SELECT 'A','5',' 1/9/2014','2014',' 1',' 2',' 2' UNION ALL

    SELECT 'A','20','1/10/2014','2014','1','2','3' UNION ALL

    SELECT 'A','60','1/10/2014','2014','1','2','3'

    ),

    GroupedData

    AS

    (

    SELECT

    SUM([Case_ship]) AS [Case_ship],

    [Trandate]

    FROM MyCTE

    GROUP BY [Trandate]

    )

    SELECT max(Case_Ship),datepart(week,Trandate) FROM GroupedData group by datepart(week,Trandate) order by datepart(week,Trandate) ;

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!