Compare two columns in two databases to insert the content of a third column into a forth one I have two tables in  different databases:
b.dbo.table1
ID
Code

w.dbo.table2:
ID 
Code2 
ID2 

I am in need of code that helps me to compare (Code) in table1 with (Code2) in table2. If they are the same then insert (ID) from table1 into (ID2) in table2.
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).