Solved

# Concetanate and IIf Function

Posted on 2011-02-14
415 Views
Hi there,

Wondering if it was possible to achieve a multiple iif function with a concatenation string. I have written the following code in order to try and obtain multiple values based on an iff statement. Basically what I am trying to achieve is for example this:

If companyname has more than one expiry dates on an agreement then my expression will write the agreement names that qualify i.e. "AgrA, AgrB" etc.
``````ContractType: IIf([AgrAExpiryDate]>0,"AgrA",+IIf([AgrBExpiryDate]>0,"AgrB",+IIf([AgrCExpiryDate]>0,"AgrC",+IIf([AgrDExpiryDate]>0,"AgrD",+IIf([AgrEExpiryDate]>0,"AgrE",+IIf([AgrFExpiryDate]>0,"AgrF",+"Other"
``````
0
Question by:databarracks
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4
• 3

Author Comment

ID: 34887066
If this makes the explanation easier, where in the relative expiry date fields in the multiple agreement types are <=Date()+90 please return the text "AgrA" OR "AgrB" OR "AgrC" but there is a high possibility that there would be two contract types expiring in the same period and therefore need to have the ability to return the two agreement types that qualify.

This as vaguely explained in my original post.
0

LVL 85

Expert Comment

ID: 34887155
You can "nest" multiple IIF statements basically by using the "False" section of the IIF to include another IIF:

IIF(MyValue=1, "Yes", IIF(MyValue=2, "No",IIF(MyValue=3,"Maybe")))

However this get exceptionally convoluted very quickly and can be a bear to manage down the road. You might be able to use the Switch function in your query:

contracttype: SWITCH(AgrEpricyDate>0, "AgrA", AgrExpiryDate>30, "AgrB")

Or you could build a function that did this, and then use that function in your query.

Note all of these can result in poor performance.
0

Author Comment

ID: 34887196
I understand nesting multiple iif functions but that doesn't enable me to return the options I require. Hmmmm, I think I may have landed myself in a pickle here. The key bit is concatenating as I have already made it return one value as indicated originally, but if I have two types of agreements expiring at the same time it would only return the first one and not both.
0

Author Comment

ID: 34887610
0

LVL 44

Accepted Solution

GRayL earned 125 total points
ID: 34890184
Try this.  I am assuming that if all of the first six tests are 0 then you want the word "Other".

Switch([AgrAExpiryDate]>0,"AgrA ") & Switch([AgrBExpiryDate]>0,"AgrB ") & Switch([AgrCExpiryDate]>0,"AgrC ") & Switch([AgrDExpiryDate]>0,"AgrD ") & Switch([AgrEExpiryDate]>0,"AgrE ") & Switch([AgrFExpiryDate]>0,"AgrF ") & IIf(IsNull(
Switch([AgrAExpiryDate]>0,"AgrA" ) & Switch([AgrBExpiryDate]>0,"AgrB ") & Switch([AgrCExpiryDate]>0,"AgrC ") & Switch([AgrDExpiryDate]>0,"AgrD ") & Switch([AgrEExpiryDate]>0,"AgrE ") & Switch([AgrFExpiryDate]>0,"AgrF")), "Other", "")
0

LVL 44

Expert Comment

ID: 34890239
I did some testing and this was the only way I could concatenate one to six results where the applicable  dates tested positive. Just remember this will fail if any of the dates are prior to 31 Dec 1899.
0

Author Closing Comment

ID: 34897082
Spot on with the recommendation and was very concise with the solution
0

LVL 44

Expert Comment

ID: 34897727
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
###### Suggested Courses
Course of the Month3 days, 12 hours left to enroll