Reputation: 309
I need to insert values from one table to another. However, when I run my command, I get this response.
Msg 207, Level 16, State 1, Line 4
Invalid column name 'table1column'.Msg 207, Level 16, State 1, Line 5
Invalid column name 'othertable1column'.
Here is my code:
insert into table2 (column2)
select column1
from table1
where table2column = table1column
and othertable2column = othertable1column
What am I doing wrong?
Upvotes: 0
Views: 1035
Reputation: 1269463
I suspect that you really want an update:
update table2
set column2 = column1
from table2 join
table1
on table2.table1column = table1.table1column and
table2.andothertable2column = table1;othertable1column;
insert
inserts new rows. update
updates values in existing rows. If you are trying to join the two tables together, then presumably the row you want is already in table2
.
Upvotes: 1