• Have you tried writing a SQL scalar function to accomplish it? That would be the way I'd begin.