We can't tell you what is wrong with your query if you don't provide your query. You should also post data in a CONSUMABLE format. That is, post a script that will insert your data into a table (preferably a temp table or table variable) as outlined in the first link in my signature.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA