Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IIf and multiple criteria 1

Status
Not open for further replies.

hyperiest

Technical User
Dec 26, 2002
35
US
Does anyone know if you can use multiple selection criteria in an IIf argument? Example: IIf(Left([PMOS],3)="91W" Or "91X"...

If this can be done, please let me know how.

Thanx.
 
Use a nested IIf like this:

IIf(Left([PMOS],3)="91W", TrueResult, IIf(Left([PMOS],3)="91X", TrueResult, FalseResult))

-Larry
 
Thanks a mil, but it didn't work. This is my code:

MOSQIASI: IIf(Left([PMOS],3)=&quot;91W&quot;,Left([PMOS],3) & IIf(Mid([PMOS],5,1<>&quot;F&quot;,Null,Mid([PMOS],5,1) & IIf(Mid([PMOS],6,2)=&quot;00&quot;,Null,Mid([PMOS],6,2),IIf(LEFT([PMOS],3)=&quot;91X&quot;, Left([PMOS],3) & Mid([PMOS],5,1) & IIf(Mid([PMOS],6,2)=&quot;00&quot;,Null,Mid([PMOS],6,2),Left([PMOS],3))

I have tried adding and subtracting parens at the end and throughout the statement, but to no avail. I keep getting that it has the wrong number of arguments.
 
hyperiest-

Every IIf() test must have a TRUE and a FALSE parameter. Several of your IIfs lack a FALSE value. It is usually easiest to start with one IIf and verify that the partial result works, then add on the next IIf.

The other big problem you have is that you are trying to concatenate Nulls. Anything plus Null equals Null, so for those FALSE arguments where you have put Nulls you need to switch them to an empty set &quot;&quot;.

I can't figure out what exactly you're trying to do, thus I'm afraid that's about as specific as I can get.

-Larry
 
Larry, I am an Army personnel officer who is sorting through Army SQL data tables to find discrepancies between authorized personnel strength from one database to another (sadly the Army has not caught on to using one central automated personnel system). I have common data across the different tables, but the data format is not common.

I am trying to select data based on specific MOS (military occupational specialty), but some of the data is concatenated (up to 9 characters with standardized placeholders for null values -- &quot;00&quot;, &quot;F&quot;, &quot;O&quot;, &quot;YY&quot;, etc.) and some of it is separated with null values instead of the standardized placeholders.

A typical MOS is as follows: 98G4L2SRU, where 98G denotes the MOS, 4 represents skill level, L denotes Linguist, 2S denotes Battle Staff qualification, RU denotes Russian language.

I am looking for all MOS's, but specifically 91W and 91X where the 5th character is &quot;F&quot; (also need those without F as a whole) and where the 7th and 8th characters are other than &quot;00&quot; (the standard placeholders for null value)--(also need those without &quot;00&quot; by specific value).

So, I want the query to return results like so:
MOS Auth
88M 75
91W 221
91WF 34
91WF2S 12
91W2S 10
91X 112

If I need to be more specific, let me know.
 
hyperiest-

Why don't you create a query that makes new fields for all the items concatenated in that expression. Your first query would have the additional fields of:
MOS:Left([PMOS],3)
Auth:Mid([PMOS],3,2)
etc., to get the string broken down. Then make a second query based on the first one that picks the records you want (MOS=&quot;91W&quot; or &quot;91X&quot;, etc.).

This avoids using a large, complicated IIf formula, but is also breaks the fields down so that you can, should the need ever arise, also pull out MOS=&quot;90Y&quot; or whatever else you might need.

-Larry
 
A slightly different process would be to generte a small procedure which is just the same logic as the (fixed) IIF statement. It is just a LOT easier to read and understand the code in a procedure than the query grid or 'ZOOM' window.

It also appears, to me, that it would be easier to set up seperate queries for the criteria, and combine the results via a union of the individual selections. Just glancing at the statementt provided, it is not even clear to me wheather the returned calculation should be a MOS, of just a flag denoting the MOS is of interest.

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Thanks to all. I will try your recommendations and get back to you to let you know which one worked best.

Tracy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top