• I've got teh same answer ad Ed Wagner does, i just processed your post through a macro so i had some consumable data.

    if you want solid help like that int he future, it's up to you to provide consumable data like this to help us generate tested code and answers.

    SET DATEFORMAT DMY

    ;WITH MyCTE([Custmoer NO],[product name], [billed date ])

    AS

    (

    SELECT convert(int,'50'),'Biscuit',convert(date,'1/4/2013') UNION ALL

    SELECT '50','Milk','10/4/2013'UNION ALL

    SELECT '50','Milk','11/4/2013'UNION ALL

    SELECT '50','Curd','15/4/2013'UNION ALL

    SELECT '50','Biscuit','14/4/2013'UNION ALL

    SELECT '50','Milk','16/4/2013'UNION ALL

    SELECT '50','Curd','21/4/2013'UNION ALL

    SELECT '50','Biscuit','19/4/2013'UNION ALL

    SELECT '50','Curd','26/4/2013'UNION ALL

    SELECT '50','Milk','28/4/2013'UNION ALL

    SELECT '50','Biscuit','30/4/2013'UNION ALL

    SELECT '40','Biscuit','1/4/2013'UNION ALL

    SELECT '40','Milk','10/4/2013'UNION ALL

    SELECT '40','Milk','11/4/2013'UNION ALL

    SELECT '40','Curd','15/4/2013'UNION ALL

    SELECT '40','Biscuit','14/4/2013'UNION ALL

    SELECT '40','Milk','6/4/2013'UNION ALL

    SELECT '40','Curd','21/4/2013'

    )

    SELECT [Custmoer NO],[product name],COUNT(*)

    FROM MyCTE

    GROUP BY [Custmoer NO],[product name]

    order by [Custmoer NO] DESC,[product name];

    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!