Link to home
Start Free TrialLog in
Avatar of ttist25
ttist25

asked on

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!  
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

<<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.
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ttist25
ttist25

ASKER

That's what it was.  I figured it out as you were posting it!  Thanks!
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.
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
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.