Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to replace letters of work with reference table column

I want to replace each letter of a column (nvarchar) with the letters defined earlier:

I got 2 tables : Data, EncodingReference

In data table I have a single column called Name with the data below:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Name
New
My
Beep

In the EncodingReference table I have 2 columns

SourceLetter TargetLetter
N E
B M

What I want to get is the following result set:

Name
EEW
My
Meep

Basically I want to replace each letter with the target letter stored in another table.

>Solution :

Possibly the following may serve your purpose using translate

select Translate(name, s, t) Name
from data d
cross apply (
  select String_Agg(sourceLetter,'')s, String_Agg(Targetletter,'')t
  from EncodingReference
)er;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading