Insert Into语句中的列名无效

时间:2014-07-15 15:39:12

标签: sql sql-server

我需要将值从一个表插入另一个表。但是,当我运行我的命令时,我得到了这个回复。

  

Msg 207,Level 16,State 1,Line 4
  列名称无效' table1column'。

     

Msg 207,Level 16,State 1,Line 5
  列名称无效' othertable1column'。

这是我的代码:

insert into table2 (column2)
   select column1
   from table1
   where table2column = table1column
   and othertable2column = othertable1column

我做错了什么?

1 个答案:

答案 0 :(得分:1)

我怀疑你真的想要更新:

update table2
    set column2 = column1
    from table2 join
         table1
         on table2.table1column = table1.table1column and
            table2.andothertable2column = table1;othertable1column;

insert插入新行。 update更新现有行中的值。如果您尝试将两个表连接在一起,那么可能您想要的行已经在table2

相关问题