Compare two columns in two databases to insert the content of a third column into a forth one
It's not clear what's the link between your 2 tables.

If the link between your tables is through Code and Code2:

UPDATE T2 SET
    ID2 = T1.ID
FROM
    b.dbo.table1 AS T1
    INNER JOIN w.dbo.table2 AS T2 ON T1.Code = T2.Code2


If the link is through ID and the comparison by Code:

UPDATE T2 SET
    ID2 = T1.ID
FROM
    b.dbo.table1 AS T1
    INNER JOIN w.dbo.table2 AS T2 ON T1.ID = T2.ID
WHERE
    T1.Code = T2.Code2


I'm assuming that you meant an UPDATE of the column ID2 when the codes match and not creating a new row just with the ID2 value (which would require an INSERT operation).