Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / May 2005

Tip: Looking for answers? Try searching our database.

Limit on iif statements?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Perico - 19 Apr 2005 19:55 GMT
I have a query make-table query that works.  However, I need to add one more
if statement and when I do, along with the additional left ), I get a message
"Query too Complex..."

Is there a limit on the number of if statements Access2003 can handle?

Here is the query that works:

SELECT tg.ImportID, tg.App_ID, tg.Equipment_ID, tg.ItemID, tg.Manufacturer1,
Manufacturer2, tg.Model_No1, tg.BTUH, tg.System, tg.Product, tg.Cooling,
tg.EER, tg.SEER, tg.IPLV, tg.HighCOP, tg.LowCOP, tg.HSPF, tg.TXV, tg.ESTier,
tg.ESRebate_AmtH, tg.ESRebate_Per_Ton, ESApprove_FlagH, IIf(([Product]="AC"
Or [Product]="HP") And ([System]="S" Or [System]="P"),

IIF(([Cooling]="W" AND [EER]>=14 AND [BTUH] >=135000), "S213",

IIF(([Cooling]="W" AND [EER]>=14 AND [BTUH] <135000), "S216",

IIf([BTUH]>240000  AND [IPLV]>=10.4,"S218",

IIf(([BTUH]>=135000 And [BTUH]<=240000) AND [EER]>=10.8 AND
[IPLV]>=11.2,"S217",

IIf(([BTUH]>=65000 And [BTUH]<135000 AND [EER]>=11),"S216",

IIf(([BTUH]<65000 AND ( [EER]>=12 Or [SEER]>=14) And  [TXV]=True) and
[Cooling]="A","S181",

IIf(([BTUH]<65000 AND ([EER]>=11.6 Or [SEER]>=14) And  [System]="P" and
[Cooling]="A"),"S182",

IIf(([BTUH]<65000 AND  (([EER]>=11.6 AND [EER]<12) Or ([SEER]>=13 AND
[SEER]<14))  And [TXV]=True),"S214",

IIf(([BTUH]<65000 AND  (([EER]>=11.3 AND [EER]<11.6) Or ([SEER]>=13 AND
[SEER]<14)) And [System]="P" And [Cooling]="A"),"S215",

IIf(( [BTUH]<65000 AND [Cooling]="A" AND  (([EER]>=11 AND [EER]<11.3) Or
([SEER]>=13)) And [System]="S"  ),"S104",

IIf(([BTUH]<65000  AND ([EER]>=11 Or [SEER]>=12) And nz([SEER],0)<13 And
[System]="P" ) AND [Cooling]="A","S105",

"NOT YET")))))))))))) AS Measure, IIf([Measure] In ('S104','S105'),1,

IIf([Measure] In ('S213','S214','S215','S216','S217','S218'),2,

IIf([Measure] In ('S181','S182'),3,0))) AS Tier, IIf([Measure] In
('S104','S105'),Format(76,"Currency"),
IIf([Measure] In ('S214','S215'),Format(95,"Currency"),
IIf([Measure] In ('S181','S182'),Format(132,"Currency"),

IIf([Measure] In ('S213'),Format(107,"Currency"),

IIf([Measure] In ('S216'),Format(71,"Currency"),
IIf(([Measure] In ('S217','S218') And
[Cooling]="A"),Format(71,"Currency"),0)))))) AS Rebate_Per_Ton INTO
acQUALIFIEDS
FROM acSAMPLE_APPLICATION AS tg;
MGFoster - 19 Apr 2005 20:34 GMT
You may want to use the Switch() function instead of the nested IIf()s:

IIf(Product IN ("AC","HP") And [System] IN ("S" "P"),
    Switch(Cooling="W" AND EER>=14 AND BTUH>=135000, "S213",
           Cooling="W" AND EER>=14 AND BTUH<135000,  "S216",
           BTUH>240000 AND IPLV>=10.4, "S218",
                 ... etc. ... ,
           BTUH<65000 AND (EER>=11 Or SEER>=12)
             AND Nz(SEER,0)<13 AND [System]="P"
             AND Cooling="A", "S105")
    ,"Not Yet") As Measure,

I used the first IIf() to determine if the Switch() function should be
run.  The Switch() function is the TruePart of the IIf() function; "Not
Yet" is the FalsePart.
Signature

MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

> I have a query make-table query that works.  However, I need to add one more
> if statement and when I do, along with the additional left ), I get a message
[quoted text clipped - 55 lines]
> acQUALIFIEDS
> FROM acSAMPLE_APPLICATION AS tg;
Duane Hookom - 20 Apr 2005 06:59 GMT
I would wrap all of this into a user-defined function for easier, more
centralized maintenance. I am much to impatient and old to manage large
IIf() or Switch() expressions.

Signature

Duane Hookom
MS Access MVP

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
[quoted text clipped - 74 lines]
>> acQUALIFIEDS
>> FROM acSAMPLE_APPLICATION AS tg;
MGFoster - 20 Apr 2005 17:30 GMT
> I would wrap all of this into a user-defined function for easier, more
> centralized maintenance. I am much to impatient and old to manage large
> IIf() or Switch() expressions.

Actually, I believe the best answer is to put all the comparison data
into a table, or tables, and just join that big table to the comparison
data table(s) to get the "S" numbers.  I didn't say that before, 'cuz I
don't know anything about the db's design/purpose, and didn't want to
design a db for the OP.
Signature

MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

Duane Hookom - 20 Apr 2005 17:39 GMT
Good point, I agree that modeling business rules in tables is the preferred
method.

Signature

Duane Hookom
MS Access MVP
--

>> I would wrap all of this into a user-defined function for easier, more
>> centralized maintenance. I am much to impatient and old to manage large
[quoted text clipped - 8 lines]
> don't know anything about the db's design/purpose, and didn't want to
> design a db for the OP.
Perico - 07 May 2005 17:30 GMT
I'm not sure how you'd do that (i.e. JOIN the comparison data to the table
for which you're trying to return the "S" data, when you have ranges
involved.  For example, let's say the Lookup table has a range of 65000 to
100000 btu to qualify (return an "S"), and the table being evaluated contains
units of various btu's.  How do you join something like that?

> > I would wrap all of this into a user-defined function for easier, more
> > centralized maintenance. I am much to impatient and old to manage large
[quoted text clipped - 8 lines]
> don't know anything about the db's design/purpose, and didn't want to
> design a db for the OP.
John Vinson - 08 May 2005 03:26 GMT
>I'm not sure how you'd do that (i.e. JOIN the comparison data to the table
>for which you're trying to return the "S" data, when you have ranges
>involved.  For example, let's say the Lookup table has a range of 65000 to
>100000 btu to qualify (return an "S"), and the table being evaluated contains
>units of various btu's.  How do you join something like that?

A "Non Equi Join" is pretty slick at this. Make your Lookup table with
three fields - LowBTU, HiBTU, ResultCode. Join it to your table with a
JOIN clause like

INNER JOIN ResultCodes
ON BTU >= ResultCodes.LowBTU AND BTU < ResultCodes.HiBTU

                 John W. Vinson[MVP]    
Perico - 13 May 2005 18:01 GMT
Thank you, John.  Very much appreciated.

> >I'm not sure how you'd do that (i.e. JOIN the comparison data to the table
> >for which you're trying to return the "S" data, when you have ranges
[quoted text clipped - 10 lines]
>
>                   John W. Vinson[MVP]    
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.