?
Solved

Count Query

Posted on 2007-10-16
1
Medium Priority
?
757 Views
Last Modified: 2012-06-21
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

0
Comment
Question by:JonMny
1 Comment
 
LVL 14

Accepted Solution

by:
Jai S earned 2000 total points
ID: 20084747
can you use a count(*) directly
select count(*)
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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question