I have a table like this one:
ID Code CodeType CodeExt
1 -S_P&S_A S_P A+B
1 -S_P&S_A S_A C
2 S_P/S_A/S_Z S_P A+B+C
2 S_P/S_A/S_Z S_A D
2 S_P/S_A/S_Z S_Z E
3 S_P S_P A
The expected output is
ID Code_new
1 -(A+B)&(C)
2 (A+B+C)/(D)/(E)
3 (A)
So I want the column Code to be replaced by CodeExt depending on CodeType.
What I tried is
SELECT ID, REPLACE(Code,CodeType,'('+CodeExt+')') AS Code_new
FROM table
but this doesn't deliver the expected output.
