John said:
I want to make a query to categorize my data for a report. Let's say I have
YesNo fields A,B, and C. On the basis of the combination of the values of
those fields I would like to give the different combinations one temporary
status value (one for each combination) in a new field. Example of the data:
ID A B C
1 Y N N
2 Y Y N
3 Y Y Y
A query should result in:
ID Status
1 Pending
2 Not OK
3 OK
Can this easily be done in one query? I can't seem to figure it out.
Thank you.
John
Create a new table to contain the status values assigned for each of the
eight combinations:
tblStatus
SID AutoNumber
A Y/N
B Y/N
C Y/N
Status Text
SID A B C Status
1 N N Y Not Allowed
2 N Y N Not Allowed
3 N Y Y Not Allowed
4 Y N N Pending
5 Y N Y Not Allowed
6 Y Y N Not OK
7 Y Y Y OK
8 N N N Not Allowed
Then you should be able to create an inner join on all three fields with
your first table (I'm calling it tblReportData):
qryShowStatus:
SELECT ID, tblReportData.A, tblReportData.B, tblReportData.C, Status
FROM tblReportData INNER JOIN tblStatus ON (tblReportData.C =
tblStatus.C) AND (tblReportData.B = tblStatus.B) AND (tblReportData.A =
tblStatus.A);
!qryShowStatus:
ID A B C Status
1 Y N N Pending
2 Y Y N Not OK
3 Y Y Y OK
Personally, I believe that each situation should be considered on its
own as to whether a calculation or a separate table is better. SQL
theorists tend to like a separate "all possibilities" table for all
situations.
Another issue is that for large tables indexes on Y/N fields might not
work as well as on other field types.
I am currently facing a similar status issue. ISO specifies that
certain information should be obtained about companies that do any of
your outsourcing. For example, "Are they ISO Certified?", "Are they a
preferred outsourcer?", "Are they D6-51991 Compliant?", "Are they a sole
source supplier?", etc. Much of this information is stored in Y/N
fields. Some of those fields taken together, along with performance
metrics, can determine an outsourcer status. If the outsourcer status
can be calculated from the Y/N fields, then it should be a calculated
field. If the customer wants to be able to select an outsourcer status
and have Access change the Y/N fields appropriately then a transition
has to be planned because existing forms assume that the user is going
to choose the Y/N values and that the status will be calculated from those.
James A. Fortune
(e-mail address removed)