TysonLPrice
Programmer
Not really a question. I made a mistake on a column in a sub select and was surprised the compiler didn't catch it. Seems like a bug to me. At the very least I wouldn't think the second select would bring back anything rather then all the rows.
Code:
create table #Select(SSN Varchar(10))
create table #SubSelect(XXX Varchar(10))
insert into #Select(SSN) values('123456780')
insert into #Select(SSN) values('123456788')
insert into #Select(SSN) values('123456787')
insert into #Select(SSN) values('123456786')
insert into #Select(SSN) values('123456785')
-- This does not return any rows
select SSN from #Select where SSN in (Select SSN from #SubSelect)
insert into #SubSelect(XXX) values('123456780')
-- This returns all rows.
-- I would have suspected the compiler would have flagged that SSN is not a column
-- in #SubSelect
select SSN from #Select where SSN in (Select SSN from #SubSelect)
Drop table #Select
Drop table #Subselect