I am not really sure about the output you are expecting
It would help if you can provide DDL of the table involved with some sample data and the expected results based on the sample data
Please check the link in my signature if you are not sure about how to provide this
I am sure you will get reply in a matter of few minutes if you provide all this
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/