• Since Lynn is too busy serving his country in Afghanistan to come back here to help you out, I'll step in.

    WITH SampleData (Projects, Customers, UpdatedBy, NewValue, UpdatedOn) AS (

    SELECT 'Project 1','Customer A','User 1',£1142.00,'01/05/2012 10:27'

    UNION ALL SELECT 'Project 1','Customer A','User 1',£1839.00,'01/05/2012 10:59'

    UNION ALL SELECT 'Project 2','Customer B','User 5',£121995.00,'05/24/2012 09:26'

    UNION ALL SELECT 'Project 3','Customer C','User 3',£20332.00,'06/26/2012 09:57'

    UNION ALL SELECT 'Project 4','Customer D','User 2',£18191.00,'05/14/2012 13:40'

    UNION ALL SELECT 'Project 4','Customer D','User 1',£46906.00,'05/18/2012 13:09'

    UNION ALL SELECT 'Project 4','Customer D','User 3',£58309.00,'06/18/2012 13:39'

    UNION ALL SELECT 'Project 4','Customer D','User 1',£76500.00,'06/19/2012 15:44'

    UNION ALL SELECT 'Project 4','Customer D','User 1',£88112.00,'07/03/2012 14:14')

    SELECT *

    FROM (

    SELECT Projects, Customers, UpdatedBy, NewValue, UpdatedOn

    ,rn=ROW_NUMBER() OVER (PARTITION BY Projects ORDER BY UpdatedOn DESC)

    FROM SampleData) a

    WHERE rn=1;


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St