How would you use the function outside the stored procedure? Have you tried doing the same inside the stored procedure? Inside or outside should make a difference.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]