Reputation: 4099
Please consider two temp-tables:
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
I would like to update table #b
with a column that marks objects that exist in #a
as well in #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
)
This however doesn't work: I keep getting the error invalid column name InTableA
??
What am I doing wrong?
Upvotes: 0
Views: 61
Reputation: 1269843
You are updating the wrong table:
update #b
--------^
set InTableA = (case when object_b in (select object_a from #a) then 1 else 0 end)
------------------------------^
Upvotes: 2