2014-07-15 181 views
0

我需要将值从一个表插入另一个表。但是,当我运行我的命令时,我得到了这个响应。Insert Into语句中的列名无效

消息207,级别16,状态1,行4
无效的列名称table1column“。

消息207,级别16,状态1,行5
无效的列名称'othertable1column'。

这里是我的代码:

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

我在做什么错?

+0

'table1'是否有字段'table1column'和'othertable1column'? –

+0

我不明白你在哪里的条件。在那里似乎有问题 –

回答

1

我怀疑你真正想要的更新:

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

insert插入新行。 update更新现有行中的值。如果您试图将两张桌子连接在一起,那么您想要的行已经在table2