• By the looks of your included T-SQL, you have gone about this in the wrong way.

    Please post the entire SQL statement, the DDL for the tables, and some sample data if possible. Here are some tips for posting. If you follow these, you will get a MUCH better response.

    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]