FederalProgrammer
Programmer
All right, let's state what I need first:
Consider a number X; here's how we get it:
Select Sum(X)
From tblBlah inner join millionOtherTables
Group BY tblBlah.someField
The Query goes through the following logic:
If contion1 is true do the following:
X/aTable.Field if contion2 is true;
X/anotherTable.Field if condition2 is false and anotherTable.Field <> 0;
If condition1 is false, simply return X.
I've got all the (IIFs) figured out, and this is not the problem: here's what i do:
SUM(iif(Cond1,
iif(cond2, x/aTable.Field, iif(anotherTable.field = 0, 0, x/anotherTable.field)), X)).
Easy enought.. right? WRONG!!
You see the divisor, aTable.Field; Well, I don't need its value, as is; I need to divide X by the total of aTable.Field for that particular group.
I've tried the following:
x/Sum(aTable.Field). However access states that I cannot have aggregate functions inside iif! I have tried moving IIFs outside of SUM; The first IIF goes through; However the 2nd one complains about the fact that "iif(Cond2" is not part of the "Group By" or whatever;
Anyways, if you've understood the problem, please drop me a line. it means a lot to have someone on the same page as me!
cheers!
Consider a number X; here's how we get it:
Select Sum(X)
From tblBlah inner join millionOtherTables
Group BY tblBlah.someField
The Query goes through the following logic:
If contion1 is true do the following:
X/aTable.Field if contion2 is true;
X/anotherTable.Field if condition2 is false and anotherTable.Field <> 0;
If condition1 is false, simply return X.
I've got all the (IIFs) figured out, and this is not the problem: here's what i do:
SUM(iif(Cond1,
iif(cond2, x/aTable.Field, iif(anotherTable.field = 0, 0, x/anotherTable.field)), X)).
Easy enought.. right? WRONG!!
You see the divisor, aTable.Field; Well, I don't need its value, as is; I need to divide X by the total of aTable.Field for that particular group.
I've tried the following:
x/Sum(aTable.Field). However access states that I cannot have aggregate functions inside iif! I have tried moving IIFs outside of SUM; The first IIF goes through; However the 2nd one complains about the fact that "iif(Cond2" is not part of the "Group By" or whatever;
Anyways, if you've understood the problem, please drop me a line. it means a lot to have someone on the same page as me!
cheers!