• We've been using the ROW_NUMBER() method for a while now and it's great for reporting purposes. Not to mention, its speed is great compared to using UDFs or inserting into a temp table within a loop.

    To get the top X records per group

    SELECT * FROM

    (SELECT ROW_NUMBER() OVER (PARTITION BY ChowID ORDER BY ChowID, EndDate) as RowNumber, ChowID, EndDate, Name FROM StatLog) as a

    WHERE a.RowNumber <= @TopCount ORDER BY a.Name, a.EndDate

    /* Anything is possible but is it worth it? */