473,396 Members | 1,724 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,396 software developers and data experts.

Nested if - in an query

I am pasting some code that I wrote to see if anyone can spot the
problem. This code figures Shifts needed to finish a set schedule
amount. Each shift is figured as 7.5 hours. It worked great until I
tried to make this a nested If function. You see, there are 4 fields
that could have a 'standard' in it. Only one has a standard in it and
I need to look at all the fields to see which one has a standard in it
and then use that standard in the calculations.

The [2004Standard] and the [NewStandard] field are calculated
correctly but the [CFInternalEstimate] and [CFSubmittedToPitts] are
not calculating anything.
Am I doing this the wrong way?

IIf(([UPC's]![2004standard]>0), _
([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*[UPC's]![2004standard]*7.5),
_
([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*[UPC's]![NewStandard]*7.5)),
_
iif(([UPC's]![CFInternalEstimate]>0),([FSAPROD_RMRESR]![RREXQY])/ _
([UPC's]![PeopleNeeded]*[UPC's]![CFInternalEstimate]*7.5), _
([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*[UPC's]![CFSubmittedToPitts]*7.5))

Any help is greatly appreciated...

Norma
Nov 13 '05 #1
5 4489
nj**********@suscom.net (Norma) wrote in message news:<20**************************@posting.google. com>...
I am pasting some code that I wrote to see if anyone can spot the
problem. This code figures Shifts needed to finish a set schedule
amount. Each shift is figured as 7.5 hours. It worked great until I
tried to make this a nested If function. You see, there are 4 fields
that could have a 'standard' in it. Only one has a standard in it and
I need to look at all the fields to see which one has a standard in it
and then use that standard in the calculations.

The [2004Standard] and the [NewStandard] field are calculated
correctly but the [CFInternalEstimate] and [CFSubmittedToPitts] are
not calculating anything.
Am I doing this the wrong way?

IIf(([UPC's]![2004standard]>0), _
([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*[UPC's]![2004standard]*7.5),
_
([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*[UPC's]![NewStandard]*7.5)),
_
iif(([UPC's]![CFInternalEstimate]>0),([FSAPROD_RMRESR]![RREXQY])/ _
([UPC's]![PeopleNeeded]*[UPC's]![CFInternalEstimate]*7.5), _
([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*[UPC's]![CFSubmittedToPitts]*7.5))

Any help is greatly appreciated...

Norma


If the 'standard' is Null or zero for the other three fields then skip
using IIF entirely:

([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*(Nz([UPC's]![2004standard])
+ Nz([UPC's]![NewStandard]) + Nz([UPC's]![CFInternalEstimate]) +
Nz([UPC's]![CFSubmittedToPitts]))*7.5

This is ugly but it's pretty compared to nesting all those IIF's.

James A. Fortune
Nov 13 '05 #2
On 26 Jul 2004 03:00:39 -0700, ja******@oakland.edu (James Fortune) wrote:
nj**********@suscom.net (Norma) wrote in message news:<20**************************@posting.google. com>...
I am pasting some code that I wrote to see if anyone can spot the
problem. This code figures Shifts needed to finish a set schedule
amount. Each shift is figured as 7.5 hours. It worked great until I
tried to make this a nested If function. You see, there are 4 fields
that could have a 'standard' in it. Only one has a standard in it and
I need to look at all the fields to see which one has a standard in it
and then use that standard in the calculations.

The [2004Standard] and the [NewStandard] field are calculated
correctly but the [CFInternalEstimate] and [CFSubmittedToPitts] are
not calculating anything.
Am I doing this the wrong way?

IIf(([UPC's]![2004standard]>0), _
([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*[UPC's]![2004standard]*7.5),
_
([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*[UPC's]![NewStandard]*7.5)),
_
iif(([UPC's]![CFInternalEstimate]>0),([FSAPROD_RMRESR]![RREXQY])/ _
([UPC's]![PeopleNeeded]*[UPC's]![CFInternalEstimate]*7.5), _
([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*[UPC's]![CFSubmittedToPitts]*7.5))

Any help is greatly appreciated...

Norma


If the 'standard' is Null or zero for the other three fields then skip
using IIF entirely:

([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*(Nz([UPC's]![2004standard])
+ Nz([UPC's]![NewStandard]) + Nz([UPC's]![CFInternalEstimate]) +
Nz([UPC's]![CFSubmittedToPitts]))*7.5

This is ugly but it's pretty compared to nesting all those IIF's.

James A. Fortune


Nz is also slower to execute than IIf, but to quote Knuth, "Premature
optimization is the root of all evil." Make it as simple and clear as
possible (so use nz) at all costs, then optimize it later if necessary.
Nov 13 '05 #3
Iif statements are formatted like this:
iif(<condition>, <do this if true>, <do this if false>)

I think that in order to accomplish what you are attempting you need
more than two iifs. It should look something like this:

IIf(([UPC's]![2004standard]>0), _
([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*[UPC's]![2004standard]*7.5),
iif(([UPC's]![NewStandard] > 0),
([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*[UPC's]![NewStandard]*7.5),
iif(([UPC's]![CFInternalEstimate]>0),([FSAPROD_RMRESR]![RREXQY])/ _
([UPC's]![PeopleNeeded]*[UPC's]![CFInternalEstimate]*7.5), _
([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*[UPC's]![CFSubmittedToPitts]*7.5))))

It might look a little neater and be easier to follow if you used
nested IF..THEN..ELSE statements. Just a thought.

The [2004Standard] and the [NewStandard] field are calculated
correctly but the [CFInternalEstimate] and [CFSubmittedToPitts] are
not calculating anything.
IIf(([UPC's]![2004standard]>0), _
([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*[UPC's]![2004standard]*7.5),
_
([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*[UPC's]![NewStandard]*7.5)),
_
iif(([UPC's]![CFInternalEstimate]>0),([FSAPROD_RMRESR]![RREXQY])/ _
([UPC's]![PeopleNeeded]*[UPC's]![CFInternalEstimate]*7.5), _
([FSAPROD_RMRESR]![RREXQY])/([UPC's]![PeopleNeeded]*[UPC's]![CFSubmittedToPitts]*7.5)) Am I doing this the wrong way?
Any help is greatly appreciated...

Norma

Nov 13 '05 #4
Steve Jorgensen <no****@nospam.nospam> wrote in message news:<a4********************************@4ax.com>. ..
Nz is also slower to execute than IIf, but to quote Knuth, "Premature
optimization is the root of all evil." Make it as simple and clear as
possible (so use nz) at all costs, then optimize it later if necessary.


Steve politely and correctly notes that I should have added, "If
you're sure the other values will be zero you can omit the Nz()
functions."

James A. Fortune
Nov 13 '05 #5
ja******@oakland.edu (James Fortune) wrote in message news:<a6**************************@posting.google. com>...
Steve Jorgensen <no****@nospam.nospam> wrote in message news:<a4********************************@4ax.com>. ..
Nz is also slower to execute than IIf, but to quote Knuth, "Premature
optimization is the root of all evil." Make it as simple and clear as
possible (so use nz) at all costs, then optimize it later if necessary.


Steve politely and correctly notes that I should have added, "If
you're sure the other values will be zero you can omit the Nz()
functions."

James A. Fortune


Thank you so much Steve and James.
I used the Nz code. It works great!

You guys are the best!!
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Forgone Conclusion | last post by:
Hi, I have a View that groups and sums up totals. This View is then nested within in another View and used (it needs to be done like this). What i need to do is to be able to vary the records...
3
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can...
12
by: Jeff Lanfield | last post by:
First of all, I apologize if coalescing is not the right term to describe my problem. I have a tree where each node has the same set of attributes (is the same entity) but child nodes should...
2
by: d2r2 | last post by:
Hi, I'm trying to run a nested (UNION) query against a MSAccessXP database (version 2002; build 10.6501.6714; SP3) In Access the SQL-statement executes just fine. When I run it in a asp-page I...
5
by: ahokdac-sql | last post by:
Hi, I'm adapting access queries to sql server and I have difficulties with the following pattern : query1 : SELECT * FROM Query2 WHERE A=@param1 query 2: SELECT * FROM Table2 WHERE B=@param2 ...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
20
by: Robert | last post by:
Need some help to stop me going around in circles on this one.... Have a nested subform (subform2) which simulates a continuous form for the record on the parent subform. Subform2 has rows of...
3
by: Frank Swarbrick | last post by:
I was just messing around trying to learn things and attempted the following: select brch_nbr , sum(case when post_flag != 'P' then amount else 0 end) as sum_amount from film.film_transactions...
9
by: P3Eddie | last post by:
Hello all! I don't know if this can even be done, but I'm sure you will either help or suggest another avenue to accomplish the same. My problem may be a simple find duplicates / do something...
0
petepell
by: petepell | last post by:
Hello all, I am developing an application in VB 2008 that works with a SQL2005 DB to store and manipulate employee data. In one section of the app I want to be able to show a treeview of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.