I would recommend that your read this article by Jeff Moden
http://www.sqlservercentral.com/articles/T-SQL/63003/
contains enough sample code to do what you want to do
If everything seems to be going well, you have obviously overlooked something.
Ron
Please help us, help you -before posting a question please read[/url]
Before posting a performance problem please read[/url]