Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Counts 1

Status
Not open for further replies.

ba4crm

Technical User
Dec 19, 2003
92
0
0
US
I have a table that has the following structure
TP RecordId Status
A 1 X
A 2 X
A 3 Y
A 4

Record 4 does not have a status. I would like to count how many records belong to TP A and also how many records for TP A have a status <> Null (or how many records have a Status = Null)

Output desired:
TP Total Count Status Null
A 4 1

Thanks
 
This should satisfy your specifications:
Code:
SELECT TP, Count(RecordID) As TotalCount, Sum(Abs(IsNull(Status))) as StatusNull
FROM [a table]
GROUP BY TP;

Duane
Hook'D on Access
MS Access MVP
 
I have a slightly different variation on this. For the TP, I cannot consider that TP "closed" unless each record has a status (<> Null). This works so far.
I have to run a report that lists out all the TPs that have a status <> Null. However, if all the records have a status of "Cancel", I do not want that TP to show up in this list.
 
lists out all the TPs that have a status <> Null. However, if all the records have a status of "Cancel", I do not want that
Code:
SELECT TP, Count(*) As TotalCount
FROM [a table]
GROUP BY TP
HAVING Count(RecordID)=Count(*)
AND Sum(IIf(Status & ''='Cancel',1,0))<Count(*)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top