By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,638 Members | 1,983 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,638 IT Pros & Developers. It's quick & easy.

Query Count Function

P: n/a
I have a table where Im counting records that have a two certain
criteria. My Question is, If one criteria is met, but the other isnt
instead of not retrieving the record can the count value return "0"?
Ie

My query is as below.

Employee ID --->no criteria to meet
Shift = B
Pass = True (its a check box)
Name --(Count function) no criteria to meet

If an employee is on B shift and has passed it returns the number of
passed. But if a user is on B shift and has not passed any audits it
doenst return the record. I would like it to return the record with a
value of "0". This will allow me to match it to my second failed
query.

Any suggestions?

Thanks,

Dave

Jan 19 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Essentially, you have 2 separate queries, but you want them to be in the
same result set. One query returns a count if conditions are met, the
other query returns a 0 value if the conditions are not met. If you
want the results in the same result set all you have to do is to combine
these 2 queries in a Union Query:

select Name, count(*) cnt from tblx where shift = 'B' And Pass = True
Group By Name
Union All
Select Name, 0 cnt from tblx where shift = 'B' And Pass = False Group By
Name

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jan 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.