Reputation: 3304
Can anyone suggest the syntax for the below IF statement,
IIf
( Cur_Insert_Cost,
Cur_Insert_Cost/Cur_Insert_Edges,
Cur_Regrindable_Cost/(Cur_Regrinds_Possible+1)
) AS Cur_Cost_Edge_Regrind
the above line is from the Excel report with Ms-Access DB
I didn't understand the condition part....!!!
Cur_Insert_Cost, Cur_Insert_Edges, Cur_Regrindable_Cost ... etc are column names
Upvotes: 0
Views: 72
Reputation: 524
The statement says that the value of column Cur_Cost_Edge_Regrind
is:
Cur_Insert_Cost/Cur_Insert_Edges
if Cur_Insert_Cost
is TRUE (or 1)Cur_Regrindable_Cost/(Cur_Regrinds_Possible+1)
if Cur_Insert_Cost
is FALSE (or 0)Hope that helps...
Upvotes: 0
Reputation: 6006
The test is if Cur_Insert_Cost is seen as being empty for false or whatever Access counts as false.
So it may mean Cur_Insert_Cost = NULL, 0, '', false (I guess I forget some alternatives)
As you can see the first part uses is and IIRC Cur_Insert_Cost applied to NULL will give an exceptoin (but that's just from my memory)
Upvotes: 0
Reputation: 216303
IIF is a ternary operator. It is composed of three parts separated by comma
iif(expression, truepart, falsepart)
In your case it means:
if Cur_Insert_Cost is not zero then
return the result of the expression Cur_Insert_Cost/Cur_Insert_Edges
else
return the result of the expression Cur_Regrindable_Cost/(Cur_Regrinds_Possible+1)
the result will be named in the query as Cur_Cost_Edge_Regrind
Upvotes: 4