Posted on 2007-10-16
I have the following query that will return employees that are showing Status T but have user accounts that are enabled. I want to count the records that it returns and if there are any send an email. How can I get a count of the records I have tried a few things but It gives me an error on "and UserAccountControl & 2=0"
WHEN useraccountcontrol & 2 =2 THEN 'Disabled'
When UserAccountControl & 2=0 then 'Enabled'
END as AccountStatus
FROM OPENQUERY( ADSI,'SELECT emplstatus,SAMAccountName,displayname,sn,userAccountControl FROM ''LDAP://'' WHERE objectCategory = ''Person'' AND objectClass = ''user'' order by name')
where emplstatus='T' and UserAccountControl & 2=0 order by displayname