Solved

Concetanate and IIf Function

Posted on 2011-02-14
8
390 Views
Last Modified: 2012-08-14
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"

Open in new window

0
Comment
Question by:databarracks
  • 4
  • 3
8 Comments
 

Author Comment

by:databarracks
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 84
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

by:databarracks
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:databarracks
ID: 34887610
Could someone please help?
0
 
LVL 44

Accepted Solution

by:
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

by:GRayL
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

by:databarracks
ID: 34897082
Spot on with the recommendation and was very concise with the solution
0
 
LVL 44

Expert Comment

by:GRayL
ID: 34897727
Thanks, glad to help
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question