I have 2 tables:
id | bsi | cell
1 | 45 | NULL
2 | 23 | 600-1167
3 | 47 |
4 | 89 | 501- -
5 | 98 | 603-5670
I would like to replace cell values with data from another colum in another table matching both tables by bsi
Here is my 2nd table:
id | bsi | contact
1 | 45 | 610-5896
2 | 23 | 605-4567
3 | 47 | NULL
4 | 89 | 689-9089
5 | 98 | NULL
I would like each value in the first table replaced with the new value in 2nd table also the value where both tables match in bsi code ie to replace the NULL and '501- -' with the new value once there is one in the 2nd table.
So result should be an updated table as follows:
id | bsi | cell
1 | 45 | 610-5896
2 | 23 | 605-4567
3 | 47 | NULL
4 | 89 | 689-9089
5 | 98 | 603-5670
I have tried this query but it only replaces the new values and seems to write null values for items that are in table1 and not table2. I want to keep the table1 values that are in table 1 but not table 2.
UPDATE Table1
SET Table1.cell = Table2.Contact
FROM Table1 INNER JOIN Table1 ON Table1.bsi = Table2.bsi