We don't have any idea how your tables look like and what are the column names
Can you provide us the DDL of the tables involved along with some sample data and the expected results based on the sample data
That will help us provide you a tested solution back
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/