[AccessD] Using IIF in SQL

Joe Rojas JRojas at tnco-inc.com
Wed Feb 2 09:44:51 CST 2005


Access 2000

Below is SQL query that uses IIF to determine the value of a column.

SELECT DMRCCRLog.DocumentNum, DMRCCRLog.DocumentType, IIF(DMRCCRLog.OperNum
= 9992, tblDMRCCROperators.OperNum, DMRCCRLog.OperNum) AS OperatorNum
FROM DMRCCRLog LEFT JOIN tblDMRCCROperators ON (DMRCCRLog.DocumentNum =
tblDMRCCROperators.DocNum) AND (DMRCCRLog.DocumentType =
tblDMRCCROperators.DocType
WHERE DMRCCRLog.DocumentType = "DMR";

I have a form that allows a user to select the operator from a defined list.
In the case where there is more than one operator needs to be recorded they
can select an operator from the listed called "Multiple Operators" which
when they do this a form pops up that lets them select the multiple
operators and the operators are stored in tblDMRCCROperators. The above
query is used to combine the two tables and return one column that has the
operator number. It works just fine.

I want to add another join to retrieve the operator's name. "INNER JOIN
Employees ON Employees.EmpID = OperatorNum"
When I try to do this, Access yells at me saying that "Employees.EmpID =
OperatorNum" is an invalid join expression.
I assume it is because I am using a column alias in the join expression.
I tried to use "Employees.EmpID = IIF(DMRCCRLog.OperNum = 9992,
tblDMRCCROperators.OperNum, DMRCCRLog.OperNum)" and that failed.

I can achieve my goal by saving the above SQL statement to a query and
referencing it in a new query, but I was wondering if it is possible to do
everything in one query.

Thanks,

JR




This electronic transmission is strictly confidential to TNCO, Inc. and
intended solely for the addressee. It may contain information which is
covered by legal, professional, or other privileges. If you are not the
intended addressee, or someone authorized by the intended addressee to
receive transmissions on behalf of the addressee, you must not retain,
disclose in any form, copy, or take any action in reliance on this
transmission. If you have received this transmission in error, please notify
the sender as soon as possible and destroy this message. While TNCO, Inc.
uses virus protection, the recipient should check this email and any
attachments for the presence of viruses. TNCO, Inc. accepts no liability for
any damage caused by any virus transmitted by this email.



More information about the AccessD mailing list