I have a column like this:
vars
-----------
|A|B|A|D|AB|B...
I want to replace one var (e.g: the one in 3rd position, which happens to be A) but keep any other A's. The position is determined by a variable. So I should get:
vars
-----------
|A|B|D|AB|B...
I know I should use REPLACE and possibly SUBSTRING_INDEX, but I can't figure out how. Here's what I've tried: Let's say :pos=3;
vars = REPLACE(vars, (SUBSTRING_INDEX(SUBSTRING_INDEX(vars, '|', :pos), '|', -1)), '')
But this actually replaces all other characters and keeps the one I need replaced.
UPDATE: Mind that I don't know what var I want to replace, only its position.
UPDATE 2:
vars = Concat(substring(vars ,1,:pos-1), substring(vars,:pos+2))
This does the trick but I forgot to mention the vars are not always |A and |B etc., but also |AB, |AC... So the position shouldn't always move by one character, but until the next |
.