• Sounds like homework...

    Would you please show us what you've tried so far and where you get stuck?

    To refer to the most recent row, you could either use an outer join or try the CROSS APPLY approach (if you're familiar with it).

    A good starting point would be ready to use table definition and some sample data as described in the first link in my signature...



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]