Starting with that idea of a small table with the replacements, might it be possible to do this using a CTE ?