MS SQL replace sequence of same characters inside Text Field (TSQL only)

Posted by zmische on Stack Overflow See other posts from Stack Overflow or by zmische
Published on 2010-03-17T22:55:36Z Indexed on 2010/03/17 23:01 UTC
Read the original article Hit count: 286

Filed under:
|

I have a text column varchar(4000) with text: 'aaabbaaacbaaaccc' and I need to remove all duplicated chars - so only one from sequence left: 'abacbac'

It should not be a function, Procedure or CLR - Regex solution. Only true SQL select.

Currently I think about using recursive WITH clause with replace 'aa'->'a', 'bb'->'b', 'cc'->'c'.

So recursion should cycle until all duplicated sequences of that chars would be replaced.

DO you have another solution, perhaps more Permormant one?

PS: I searched through this site about different replace examples - they didnt suit to this case.

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about sql-server-2005