【问题标题】:Invalid column name on Insert Into statementInsert Into 语句中的列名无效
【发布时间】:2014-09-05 21:34:48
【问题描述】:

我需要将值从一个表插入到另一个表。然而,当我运行我的命令时,我得到了这个响应。

消息 207,第 16 层,状态 1,第 4 行
列名“table1column”无效。

消息 207,第 16 层,状态 1,第 5 行
列名“othertable1column”无效。

这是我的代码:

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

我做错了什么?

【问题讨论】:

  • table1 是否有字段 table1columnothertable1column
  • 我不明白您的where 条件。好像有什么问题

标签: sql sql-server


【解决方案1】:

我怀疑你真的想要更新:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-04
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-21
    • 1970-01-01
    相关资源
    最近更新 更多