Update table with values from other table

jlai

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?

Giorgi Nakeuri

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Update Table column with values for other column

From Dev

PLSQL UPDATE BASED ON ROWS FROM OTHER TABLE

From Dev

Update table from other tables in SAS

From Dev

SQL - Update table values from values in another table

From Dev

Count (*) rows based on values from other table

From Dev

Update table using random of multiple values in other table

From Dev

Update table with values from other table

From Dev

How to update SQL table from other table when they are on different servers

From Dev

MySQL: Get last update id from a table to insert it in an other table

From Dev

MySQL - Update table values from another table

From Dev

UPDATE 2 columns of a table of values from a table

From Dev

MySQL UPDATE in sequence with values from same table

From Dev

Query for Insert into using values from other table

From Dev

MYSQL Update Column with higher values from other table

From Dev

Update a table with data from other table with multiple conditions?

From Dev

update table with values from 2 other tables

From Dev

Update record in sql table with a sum of values from other table

From Dev

update value from a table if from other two table values match

From Dev

Update a table with values from a related table

From Dev

MySQL: Get last update id from a table to insert it in an other table

From Dev

getting values from one table to other

From Dev

How Could I Update a table with conditions from other table

From Dev

Update a third table from two other tables

From Dev

Access: UPDATE column with values from another table

From Dev

Update all rows on table based on value from other table that gets multiple values from third table

From Dev

Update table based on values of column in other 2 table

From Dev

update values of sql table using the values from the same table

From Dev

Update a table based on values from a other table

From Dev

Update SQL Server Table Row by row from values of other table with joins

Related Related

  1. 1

    Update Table column with values for other column

  2. 2

    PLSQL UPDATE BASED ON ROWS FROM OTHER TABLE

  3. 3

    Update table from other tables in SAS

  4. 4

    SQL - Update table values from values in another table

  5. 5

    Count (*) rows based on values from other table

  6. 6

    Update table using random of multiple values in other table

  7. 7

    Update table with values from other table

  8. 8

    How to update SQL table from other table when they are on different servers

  9. 9

    MySQL: Get last update id from a table to insert it in an other table

  10. 10

    MySQL - Update table values from another table

  11. 11

    UPDATE 2 columns of a table of values from a table

  12. 12

    MySQL UPDATE in sequence with values from same table

  13. 13

    Query for Insert into using values from other table

  14. 14

    MYSQL Update Column with higher values from other table

  15. 15

    Update a table with data from other table with multiple conditions?

  16. 16

    update table with values from 2 other tables

  17. 17

    Update record in sql table with a sum of values from other table

  18. 18

    update value from a table if from other two table values match

  19. 19

    Update a table with values from a related table

  20. 20

    MySQL: Get last update id from a table to insert it in an other table

  21. 21

    getting values from one table to other

  22. 22

    How Could I Update a table with conditions from other table

  23. 23

    Update a third table from two other tables

  24. 24

    Access: UPDATE column with values from another table

  25. 25

    Update all rows on table based on value from other table that gets multiple values from third table

  26. 26

    Update table based on values of column in other 2 table

  27. 27

    update values of sql table using the values from the same table

  28. 28

    Update a table based on values from a other table

  29. 29

    Update SQL Server Table Row by row from values of other table with joins

HotTag

Archive