I work at a school and we are trying to run a query to see all students that should be starting in the next week who don't already have an AD account (we use ID numbers in the pager field and so search on that). We have linked SQL to Ad so we can run these queries and never had any issue but when I run the following I don't get any results.
select *
from FutureStudents
where id not in (select * from OPENQUERY(ADSI, '
SELECT pager
FROM ''LDAP://OU=students,DC=stcatherines,DC=net,DC=au''
WHERE objectCategory = ''Person''
AND objectClass = ''user'' '
)
)
When I run the not in command I expect that I should get one result but I do not. But if I change the query to in (instead of not in) I do get all the students that are in the table who have accounts. Plus at the same time as running these queries I have done a simple query looking for the pager in AD that I have been moving in order to get a result and when the account is in the student OU I get a result and when it is moved I do not.
So I am fairly sure is something to do with the not in statement. Am I using the right statement or is there something different I should be doing to get true results?