473,395 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Using multiple OR statements in IIF, or nesting

Hey, all.

I've tried both of the following methods, but neither is working. Suggestions?

Expand|Select|Wrap|Line Numbers
  1.   =IIf([transfer_to]=0,[amount],IIf([transfer_to]=[current_investorID],[amount],IIf([current_typeID]<6,[amount],0)))
  2. =IIf([transfer_to]=0 Or ([transfer_to]=[current_investorID]) Or [current_typeID]<6,[amount],0)
Basically if any of the conditions are true, insert [amount], if not insert 0.

Whenever I add the [current_typeID] option everything breaks. Thanks!
Feb 28 '08 #1
4 26213
I think, because of the relationships of fields/controls, this works:

Expand|Select|Wrap|Line Numbers
  1. =IIf(([transfer_to]=0 Or [transfer_to]=[current_investorID]) And [current_typeID]<6,[amount],0)
Feb 28 '08 #2
Delerna
1,134 Expert 1GB
I think if you think about the result you wanted and look at the way the three attempts are put together then you will find the answer there.

For example
in 2) you said if any of these 3 things is true then this otherwise this
in 3) you said if either of these 2 things is true AND this is true then this otherwise do this
These are totally different!

Structuring logical equations correctly can be quite tricky sometimes.
Feb 29 '08 #3
Delerna,

Once again you are quite right. My 3rd statement did NOT work, but neither does my 2nd statement. Any suggestions? Where am I going wrong?
Feb 29 '08 #4
Stewart Ross
2,545 Expert Mod 2GB
...Whenever I add the [current_typeID] option everything breaks...
Hi Talktozee. What do you mean when you say everything breaks?

As Delerna said, your statements 1 and 2 are quite different to statement 3, which as he pointed out was only true if either of the first two conditions AND the third condition were true.

As it is difficult to see the structure of a linear IIF statement I broke down your statement 1 into its logical IF-THEN-ELSE equivalent, then took out the redundant statements and reformed an IIF from the result. It is quite telling...
Expand|Select|Wrap|Line Numbers
  1. If [transfer_to]=0 then 
  2.     return [amount]
  3. elseif [transfer_to]=[current_investorID] then
  4.     return [amount]
  5. elseif [current_typeID]<6
  6.     return [amount]
  7. else
  8.    return 0
  9. endif
removing the redundant ELSEIFs by ORing the conditions together
Expand|Select|Wrap|Line Numbers
  1. If ([transfer_to]=0) OR ([transfer_to]=[current_investorID]) OR ([current_typeID]<6) then
  2.     return amount
  3. else
  4.     return 0
  5. endif
which in IIF form is just
Expand|Select|Wrap|Line Numbers
  1. IIF(([transfer_to]=0) OR ([transfer_to]=[current_investorID]) OR ([current_typeID]<6), 
  2. amount, 0)
identical to your statement 2 that you say does not work. As Delerna pointed out, getting the logic right is difficult, sometimes, and I wonder if you are testing the right types of values, as your statements 1 and 2 are logically equivalent?

-Stewart
Feb 29 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Profetas | last post by:
Hi, Nested statements helps to generate complex source code, what is the nesting limit that you normally consider? I know that the Halsted and McCabe analyses can define the acceptable level,...
24
by: sureshjayaram | last post by:
In some functions where i need to return multiple error codes at multiple places, I use multiple return statements. Say for ex. if (Found == 1) { if (val == -1) return error1; } else { if...
1
by: rudykayna | last post by:
I'm having trouble executing multiple DDL statements in one SQL file. I've been using ExecuteNonQuery() but it does not seem to like the "GO" statements in my SQL file. I need to keep the "GO"...
22
by: Technoid | last post by:
Is it possible to have a conditional if structure nested inside a conditional switch structure? switch(freq) { case 1: CASENAME if (variable==1) { do some code }
1
by: arthy | last post by:
Hi, Is it possible to execute multiple statements on to the database using a single dbconnection object.what is the drawback in using .If not possible ,then how can the execution of multiple...
17
by: nergal | last post by:
What is a good programming style in C to handle multiple returns in a function that returns different values? - To have a variable that is set to the return value, which is in the end of the...
3
by: Hrvoje Niksic | last post by:
I often have the need to match multiple regexes against a single string, typically a line of input, like this: if (matchobj = re1.match(line)): ... re1 matched; do something with matchobj ......
11
by: O.B. | last post by:
Does C# support anything like PHP's break command that optionally accepts a parameter specifying how many loops to break out of?
3
by: Israel | last post by:
I always wondered why the using command can only take one object. I always find that this isn't sufficient for drawing so I end up always disposing in my finally block but then I have to remember...
11
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
Can switch statements be nested? I've got a large routine that runs off of a switch statement. If one of the switches in switch #1 is true, that enters switch statement #2. Some of the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.