I have a table 1
where I have to replace some data in a column with data from a table 2
.
Table 1
A | B
-----------------------------
Test A1 | 123SOMETEXT
Test A2 | 456OTHERTEXT
Test A3 | 789MORETEXT
Table 2
B_old | B_new
-----------------------------
123 | ABC
456 | DEF
789 | GHI
Using this example I have to replace for example 123SOMETEXT
in column B
of table 1
with ABCSOMETEXT
and so on. How can I do that?
This should work:
update t1 set B = replace(B, cast(t2.B_old as varchar(10)), c2.B_new)
from Table1 t1
join Table2 t2 on t1.B like cast(t2.B_old as varchar(10)) + '%'
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments