2014-07-15 239 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