[英]Invalid column name on Insert Into statement
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 消息207,第16级,州1,第4行
Invalid column name 'table1column'. 无效的列名“ table1column”。Msg 207, Level 16, State 1, Line 5 消息207,第16级,州1,第5行
Invalid column name 'othertable1column'. 无效的列名“ othertable1column”。
Here is my code: 这是我的代码:
insert into table2 (column2)
select column1
from table1
where table2column = table1column
and othertable2column = othertable1column
What am I doing wrong? 我究竟做错了什么?
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. insert
插入新行。 update
updates values in existing rows. update
更新现有行中的值。 If you are trying to join the two tables together, then presumably the row you want is already in table2
. 如果您试图将两个表连接在一起,则可能您想要的行已经在table2
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.