My SQL Server database input values follow a pattern of where the first position is a character and then followed by number. I want replace the first character with another character or characters . For example:
input
Q234567888
R264747848
B264712481
output
I234567888
I264747848
U264712481
Potential values for the first position are [A-Z]
.
I am looking for an option without using multiple REPLACE
statement and not using CASE
.
If I use CASE
, I will have to check 26 cases or if I use REPLACE
in a nested way, I may end up using 26 REPLACE
statements. I am trying to avoid these.
Please suggest any better way to do achieve the results.
Best Answer
Create a mapping between the old value and the new value in a table value constructor and use stuff to replace the character.