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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 nested query

Author  Topic 

sharona
Yak Posting Veteran

75 Posts

Posted - 2011-09-01 : 10:50:36
im having a bit of trouble with this simple nested query below
i need to find out what funds are not assigned to the users
the userpermission table has the fund code assigned. the fund table is the lookup table,
when i do an outer join i still only get what is assigned to the users. i thought a nested query would work. when i use in i get all the funds assigned, when is use NOT IN i get nothing. any ideas?

SELECT
FundCode,
UserCode,
RoleCode
FROM
dbo.UserPermission
WHERE FundCode IN (SELECT FundCode FROM Fund)
AND UserCode ='NAG'

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-09-01 : 10:52:40
[code]
select *
from Fund f
where not exists
(
select * from UserPermission u where u.FundCode = f.FundCode
)
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sharona
Yak Posting Veteran

75 Posts

Posted - 2011-09-01 : 11:06:45
thank you
Go to Top of Page
   

- Advertisement -