R
Randall Arnold
I posted this question recently and thought I'd solved it myself but it turns out my solution has bugs. I'm hoping that someone can help.
I have two tables involved in my query. One is a list of audit categories, as shown:
Table 1 Category
Audit Checklist
Housekeeping
MIS
PMs
Procedure
Process
Prod Handling
Prod ID
Safety
Specs
The other table is a list of audit failures, that is essentially composed of a record ID (unique bigint ), a date (can be repeated), the category of an audit failure (nvarchar pulled from Table 1) and the defect type (nvarchar pulled from another table I'm not concerned with at this point).
On any given day, there can be numerous categorical failure records. Any category can be represented up to 4 times, or not at all depending on failures. In the failure table there will only be failures shown so I am not concerned with days of zero failures. So the group of records I retrieve per day can have anywhere from 1 to 40 rows.
I want my result set to count the number of times a category is represented per day. This also includes a count of zero (0) for the days that any category had no failures.
I have not been able to get a query to do this accurately. I can easily count the number of times a categorical failure has been entered per day, but I can't count the number of times per day that no failure occurred for any given categories. I have tried all sorts of logic and joins from all sorts of examples and nothing gets me there.
I have to believe this is possible-- I just need some guidance. Any ideas?
Thanks,
Randall Arnold
I have two tables involved in my query. One is a list of audit categories, as shown:
Table 1 Category
Audit Checklist
Housekeeping
MIS
PMs
Procedure
Process
Prod Handling
Prod ID
Safety
Specs
The other table is a list of audit failures, that is essentially composed of a record ID (unique bigint ), a date (can be repeated), the category of an audit failure (nvarchar pulled from Table 1) and the defect type (nvarchar pulled from another table I'm not concerned with at this point).
On any given day, there can be numerous categorical failure records. Any category can be represented up to 4 times, or not at all depending on failures. In the failure table there will only be failures shown so I am not concerned with days of zero failures. So the group of records I retrieve per day can have anywhere from 1 to 40 rows.
I want my result set to count the number of times a category is represented per day. This also includes a count of zero (0) for the days that any category had no failures.
I have not been able to get a query to do this accurately. I can easily count the number of times a categorical failure has been entered per day, but I can't count the number of times per day that no failure occurred for any given categories. I have tried all sorts of logic and joins from all sorts of examples and nothing gets me there.
I have to believe this is possible-- I just need some guidance. Any ideas?
Thanks,
Randall Arnold