Quantcast
Channel: Microsoft Community - Super Fresh
Viewing all articles
Browse latest Browse all 1237235

How to Make Access Query Less Complex

$
0
0

Hello, 

After adding a few more nested IIf statements to a query, I'm receiving an error that my query is too complex. I'm wondering if anyone has any suggestions for how to simplify it. I need to make some calculations referring to data in tables and within the query. The query calculates a field with one IIf statement and then refers to it in the next. 

Here is the bit of code that's giving me trouble. I'm happy to provide more if that would be helpful. 

IIf(IsNull([qty1]),[24_mo_sales],
IIf([24_mo_sales]<[qty1],[24_mo_sales],
[Qty1])) 
AS tier1_qty, 

IIf([tier1_qty]<[24_mo_sales],
IIf(IsNull([qty2]),[24_mo_sales]-[tier1_qty],
IIf([tier1_qty]+[qty2]>[24_mo_sales],
[24_mo_sales]-[tier1_qty],[qty2])),0) 
AS tier2_qty, 

IIf([tier2_qty]+[tier1_qty]<[24_mo_sales],
IIf(IsNull([qty3]),
[24_mo_sales]-[tier1_qty]-[tier2_qty],
IIf([tier1_qty]+[tier2_qty]+[qty3]>[24_mo_sales],
[24_mo_sales]-[tier1_qty]-[tier2_qty],
[qty3])),0) 
AS tier3_qty, 

IIf([tier3_qty]+[tier2_qty]+[tier1_qty]<[24_mo_sales],
IIf(IsNull([qty4]),[24_mo_sales]-[tier1_qty]-[tier2_qty]-[tier3_qty],
IIf([tier1_qty]+[tier2_qty]+[tier3_qty]+[qty4]>[24_mo_sales],[24_mo_sales]-[tier1_qty]-[tier2_qty]-[tier3_qty],[qty4])),0) 
AS tier4_qty, 

IIf([tier4_qty]+[tier3_qty]+[tier2_qty]+[tier1_qty]<[24_mo_sales],
IIf(IsNull([qty5]),[24_mo_sales]-[tier1_qty]-[tier2_qty]-[tier3_qty]-[tier4_qty],
IIf([tier1_qty]+[tier2_qty]+[tier3_qty]+[tier4_qty]+[qty5]>[24_mo_sales],[24_mo_sales]-[tier1_qty]-[tier2_qty]-[tier3_qty]-[tier4_qty],[qty5])),0) 
AS tier5_qty, 

Thanks, 

Kit


Viewing all articles
Browse latest Browse all 1237235

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>