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, displaynam e,sn,userA ccountCont rol FROM ''LDAP://'' WHERE objectCategory = ''Person'' AND objectClass = ''user'' order by name')
where emplstatus='T' and UserAccountControl & 2=0 order by displayname
select *,
CASE
WHEN useraccountcontrol & 2 =2 THEN 'Disabled'
When UserAccountControl & 2=0 then 'Enabled'
END as AccountStatus
FROM OPENQUERY( ADSI,'SELECT emplstatus,SAMAccountName,
where emplstatus='T' and UserAccountControl & 2=0 order by displayname
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.