请考虑两个临时表:
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
??
我做错了什么?
答案 0 :(得分:2)
您正在更新错误的表:
update #b
--------^
set InTableA = (case when object_b in (select object_a from #a) then 1 else 0 end)
------------------------------^