• Wow! That's quite a set of REPLACEs. If I'm reading what you want correctly, I see two different approaches you can take here.

    The first is using the STUFF statement. http://msdn.microsoft.com/en-us/magazine/cc163473.aspx. I find it works pretty well for small numbers of replacements with varying character lengths. It's a cool function to have in your "toolbox", but please continue reading.

    It looks to me like regular expressions are what you really want. I suggest writing a .NET CLR, create an assembly for it and then write database function wrappers. I've seen this used with some ridiculously complicated pattern matches.

    Library and How-To: http://www.codeproject.com/Articles/42764/Regular-Expressions-in-MS-SQL-Server-2005-2008

    MSDN Article: http://msdn.microsoft.com/en-us/magazine/cc163473.aspx

    I don't do the .NET library exposed to SQL Server very much because I find that most things can be accomplished with normal T-SQL (I'm not looking for an argument here) but this is one of those cases where it just makes sense. Performance is pretty good, but it of course depends on how you write your .NET library. Having used regular expressions natively in Oracle 8 and 9i, I can say that the performance of this approach wins, hands down. It'll take some work to write the first time, but then you'll find yourself using it as you need it.