OK, so here’s the problem.
I have a flat table which has summary information for each department.
The only possible statuses are 1, 0 and -1.
When I run my plain vanilla SQL query I get something like this:
DEPT COUNT PERCENT TOTAL STATUS COMPLIANCY
Dept1 18 81.8 22 1 Compliant
Dept1 1 4.5 22 0 Non Compliant
Dept1 3 13.6 22 -1 Unknown
Dept2 6 85.7 7 1 Compliant
Dept2 1 14.3 7 -1 Unknown
Dept3 1 50 2 1 Compliant
Dept3 1 50 2 0 Non Compliant
Dept4 1 100 1 1 Compliant
Whenever there are records for all statuses, three rows are displayed.
But if a department does not have a particular status, then there is no row presented (obviously).
I would like to create ‘dummy’ rows in the result for those department statuses which are not present in the table. This is necessary so that I can export the results to Excel for further analysis i.e. pivots tables. Note that the “Compliancy” field is a Case statement based on Status. I’m not looking to update the table, just the result of the query.
For example, Dept1 in the above sample has all three statuses, so no rows need to be created.
Dept2 is missing a status 0 row, so I need to create a row such as:
Dept2 0 0 0 0
Likewise Dept3 needs a dummy row such as:
Dept3 0 0 0 -1
Dept4 needs 2 dummy rows such as:
Dept4 0 0 0 0
Dept4 0 0 0 -1
I don’t need a full solution, but if someone can provide the logic, that would be helpful. Though not necessary, if there’s a way to copy the “Total” amounts to the new rows that would be great.
Thanks in advance,
PaulT
I have a flat table which has summary information for each department.
The only possible statuses are 1, 0 and -1.
When I run my plain vanilla SQL query I get something like this:
DEPT COUNT PERCENT TOTAL STATUS COMPLIANCY
Dept1 18 81.8 22 1 Compliant
Dept1 1 4.5 22 0 Non Compliant
Dept1 3 13.6 22 -1 Unknown
Dept2 6 85.7 7 1 Compliant
Dept2 1 14.3 7 -1 Unknown
Dept3 1 50 2 1 Compliant
Dept3 1 50 2 0 Non Compliant
Dept4 1 100 1 1 Compliant
Whenever there are records for all statuses, three rows are displayed.
But if a department does not have a particular status, then there is no row presented (obviously).
I would like to create ‘dummy’ rows in the result for those department statuses which are not present in the table. This is necessary so that I can export the results to Excel for further analysis i.e. pivots tables. Note that the “Compliancy” field is a Case statement based on Status. I’m not looking to update the table, just the result of the query.
For example, Dept1 in the above sample has all three statuses, so no rows need to be created.
Dept2 is missing a status 0 row, so I need to create a row such as:
Dept2 0 0 0 0
Likewise Dept3 needs a dummy row such as:
Dept3 0 0 0 -1
Dept4 needs 2 dummy rows such as:
Dept4 0 0 0 0
Dept4 0 0 0 -1
I don’t need a full solution, but if someone can provide the logic, that would be helpful. Though not necessary, if there’s a way to copy the “Total” amounts to the new rows that would be great.
Thanks in advance,
PaulT
Comment