MS Access IIF instead of LEFT JOIN

Hello,

I've been working on a fairly large SQL query in Access 2007.  I've run into a snag using LEFT JOINs for my lookup tables.  More specifically, I've reached the allowable number of JOINS in Access.  

I'd like to try to use an IIF statement to try to workaround it but I'm not sure exactly how to do it correctly.  My goal is to replace my LEFT JOINS for Yes/No values with an IIF statement so I can free up some JOINS for other lookup fields.  

In an attempt to make this work, I placed the following in the "Field:" row of the column in which I'd like Yes or No returned:

MyField: IIF([MyTable].[YesNo1]="2","Yes","No")

This runs but in the returned data I get "#ERROR".  Is this possible?  If so, do you know where I've gone wrong?

Thanks!  
LVL 1
ttist25Asked:
Who is Participating?
 
Dale FyeCommented:
Or it could be that the field is numeric, not text:

instead of:

MyField: IIF([MyTable].[YesNo1]="2","Yes","No")

try:

MyField: IIF([MyTable].[YesNo1]=2,"Yes","No")


0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<This runs but in the returned data I get "#ERROR".  Is this possible?  If so, do you know where I've gone wrong?>>

  Your syntax is correct, but you most likely have a broken reference.  Open a code module in design view, click tools/references and look for any that are MISSING or BROKEN.

  If none are, check any unchecked reference, then close the DB and Access, re-open and uncheck the reference just checked.  Then compile and save.

 Then try the query.

Jim.
0
 
ttist25Author Commented:
That's what it was.  I figured it out as you were posting it!  Thanks!
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Dale FyeCommented:
So, what is the limit on the number of joins?

I've written some pretty outrageous queries, but don't think I've ever run into that problem.
0
 
Nick67Commented:
You can create queries of queries.
It might be much more mainatainable to grab some of your data, save it as a query, and then use that query in another query.
Queries behave just like tables.

A huge query with a bazillion IIF([MyTable].[YesNo1]="2","Yes","No")
will be difficult to maintain
0
 
NorieVBA ExpertCommented:
The maximum no of joins in a query is 16.

There must be some other way to do this rather than using a whole bunch of Iifs and what sounds like a lot of joins.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.