[AccessD] Using IIF in SQL

Elam, Debbie DElam at jenkens.com
Wed Feb 2 10:04:56 CST 2005


Have you tried CAST to make sure that SQL is interpreting OperatorNum as the
correct datatype?

Debbie

-----Original Message-----
From: Joe Rojas [mailto:JRojas at tnco-inc.com] 
Sent: Wednesday, February 02, 2005 9:45 AM
To: 'Access Developers discussion and problem solving'
Subject: [AccessD] Using IIF in SQL


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.
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
- JENKENS & GILCHRIST E-MAIL NOTICE - This transmission may be: (1) subject
to the Attorney-Client Privilege, (2) an attorney work product, or (3)
strictly confidential. If you are not the intended recipient of this
message, you may not disclose, print, copy or disseminate this information.
If you have received this in error, please reply and notify the sender
(only) and delete the message. Unauthorized interception of this e-mail is a
violation of federal criminal law. 
This communication does not reflect an intention by the sender or the
sender's client or principal to conduct a transaction or make any agreement
by electronic means.  Nothing contained in this message or in any attachment
shall satisfy the requirements for a writing, and nothing contained herein
shall constitute a contract or electronic signature under the Electronic
Signatures in Global and National Commerce Act, any version of the Uniform
Electronic Transactions Act or any other statute governing electronic
transactions.



More information about the AccessD mailing list