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-04-04 : 09:08:33
I am trying to write a query which verifies which obj,sub combination
in upload_generalexpense does not correspond to the l5account,l5sub combination in d_accounts.

I know that my query below should yield one result, but does not..
Can someone let me know what the issue is...
Many thanks


select ltrim(rtrim(OBJ + ''+ Sub)) from iPlan.dbo.Upload_GeneralExpense a
where BusinessUnitID in
(select BusinessUnitID from biprod.dbo.D_BusinessUnits where LEID = 02010 and SBLID = 'PUA' and Year = '2011')


and not exists (select ltrim(rtrim(L5Account + '' + L5Sub)) from biprod.dbo.D_Accounts where LEID = '02010')

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-04-04 : 09:31:30
You may need to change your not exists clause to something like this:
and not exists 
(select ltrim(rtrim(L5Account + '' + L5Sub)) from biprod.dbo.D_Accounts b where LEID = '02010'
and a.ltrim(rtrim(OBJ + ''+ a.Sub)) = ltrim(rtrim(b.L5Account + '' + b.L5Sub)))
I am partially guessing because I don't have enough information about the logic you are trying to implement
Go to Top of Page
   

- Advertisement -