I don't think we can help you without create table scripts, representative data inserts and your actual and expected results from the statement execution.
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service