• I'd agree, probably best to avoid cursors. (Most) anytime you can offload iterative processing from the database into true recursive techniques using a different tool you're going to be better off.

    Also, would it be better to use the REPLACE() function rather than PATINDEX()?