Link to home
Start Free TrialLog in
Avatar of JonMny
JonMny

asked on

Count Query

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"



select *,
CASE
  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

ASKER CERTIFIED SOLUTION
Avatar of Jai S
Jai S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial