This should be a simple one, though I didn't quite find a suitable solution.
I need to implement a (rather) simple replacement using SQL (SQL Server) as follows. Imagine you have a string that looks like:
'This is a simple example where aaa[0004] should become aaa[4] and b[0],c[1] should remain unchanged'
In other words, a pattern [0004] should become [4].
I initially thought of making the replacing like:
SET @MyString = REPLACE(@MyString,'[0','[') ;
but, even before testing it, I realized that it would also convert [0] to [], which is not want I want.
I know how to do it quite simply in PL/SQL, but in SQL Server I'm having difficulties.
[0, from there], and if there are digits in-between, replace the first[0with[. Then loop till no more such cases were found. That would work, but its ugliness causes me pain.