I have the following example code:
create table #tempmembers (
memberid int
)
update Members set
Member_EMail = NULL
where Member_ID in (select member_id from #tempmembers)
The subselect contains an error, since #tempmembes does not contain a column named member_id, but the sql statements run WITHOUT any errors and update no rows.
If I then add just ONE row to #tempmembers:
create table #tempmembers (
memberid int
)
insert into #tempmembers select 1
update Members set
Member_EMail = NULL
where Member_ID in (select member_id from #tempmembers)
it still runs without any errors – but this time ALL records in Members will be affected.
Why does the SQL statement not fail completely? And if the failing subselect is evaluated to NULL – should updating all rows in Members not only occur if it had been:
update Members set
Member_EMail = NULL
where Member_ID not in (select member_id from #tempmembers)
It’s inheriting
member_idfrom the outer query so is equivalent to:This will fail as expected: