比较临时表中的值;相应地更新表

时间:2014-05-31 13:34:37

标签: sql sql-server sql-server-2008

请考虑两个临时表:

select object_a into #a from dba.object_a group by object_a

object_a
--------
123
456
789

select object_b into #b from dba.object_b group by object_b

object_b
--------
123
999

我想更新表格#b,其中的列标记#a以及#b中存在的对象:

alter table #b add InTableA int;

update #a set InTableA = (
  case when object_a in (select object_a from #a) then 1 else 0 end
)

然而,这不起作用:我不断收到错误invalid column name InTableA ??

我做错了什么?

1 个答案:

答案 0 :(得分:2)

您正在更新错误的表:

update #b
--------^
    set InTableA = (case when object_b in (select object_a from #a) then 1 else 0 end)
------------------------------^