Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 NOT EXISTS

Author  Topic 

tariq2
Posting Yak Master

125 Posts

Posted - 2011-07-18 : 11:25:59
There is something wrong with my NOT EXISTS statement below.
Any help is much appreciated...

I have exec. two statements with the same data.

The first LEFT OUTER JOIN yields expected results.
In contrast, the second NOT EXISTS yields no results.



select * from iPlan.dbo.upload_generalexpensetest a left outer join BIProd.dbo.D_BusinessUnits b
on a.BusinessUnitID = b.BusinessUnitID where b.BusinessUnitID is NULL


select * from iPlan.dbo.upload_generalexpensetest where LEID = '27002' AND NOT EXISTS
(select * from D_BusinessUnits where LEID = '27002')


Thank you



jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-07-18 : 11:59:00
You still need to link (correlate) the 2 queries

select * from iPlan.dbo.upload_generalexpensetest a where LEID = '27002' AND NOT EXISTS
(select * from D_BusinessUnits b where a.BusinessUnitID = b.BusinessUnitID
and a.leid = b.leid)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -