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

To Complex of a query

ED
I am attempting to to write a query that has a numerous nested IIf
statements. The problem that I am having is that it is to long of a
query to be built in design mode and when I build it in sql mode after
a certain point it give me the error message that the expression is to
complex. Below is the sql code that I am using (this works so far,
anything added to the code will give me the to complex error message.)

SELECT [Work Order by Activity_Quantity].WONUM, [Total Hours per Work
Order].[Total Hrs per WO], Sum((IIf([Total Hours per Work
Order]![Month]=1,IIf([Work Order by Activity_Quantity]![Activity
Quantity]>1,(1*[Activity Type Index Static Table]![Jan Index])+([Work
Order by Activity_Quantity]![Activity Quantity]-1)*[Activity Type
Index Static Table]![Jan Index]*[Activity Type Index Static
Table]![Secondary Mutiplier],[Activity Type Index Static Table]![Jan
Index]),(IIf([Total Hours per Work Order]![Month]=2,IIf([Work Order by
Activity_Quantity]![Activity Quantity]>1,(1*[Activity Type Index
Static Table]![Feb Index])+([Work Order by
Activity_Quantity]![Activity Quantity]-1)*[Activity Type Index Static
Table]![Feb Index]*[Activity Type Index Static Table]![Secondary
Mutiplier],[Activity Type Index Static Table]![Feb Index]),(IIf([Total
Hours per Work Order]![Month]=3,IIf([Work Order by
Activity_Quantity]![Activity Quantity]>1,(1*[Activity Type Index
Static Table]![Mar Index])+([Work Order by
Activity_Quantity]![Activity Quantity]-1)*[Activity Type Index Static
Table]![Mar Index]*[Activity Type Index Static Table]![Secondary
Mutiplier],[Activity Type Index Static Table]![Mar Index]),(IIf([Total
Hours per Work Order]![Month]=4,IIf([Work Order by
Activity_Quantity]![Activity Quantity]>1,(1*[Activity Type Index
Static Table]![Apr Index])+([Work Order by
Activity_Quantity]![Activity Quantity]-1)*[Activity Type Index Static
Table]![Apr Index]*[Activity Type Index Static Table]![Secondary
Mutiplier],[Activity Type Index Static Table]![Apr Index]),(IIf([Total
Hours per Work Order]![Month]=5,IIf([Work Order by
Activity_Quantity]![Activity Quantity]>1,(1*[Activity Type Index
Static Table]![May Index])+([Work Order by
Activity_Quantity]![Activity Quantity]-1)*[Activity Type Index Static
Table]![May Index]*[Activity Type Index Static Table]![Secondary
Mutiplier],[Activity Type Index Static Table]![May Index]),(IIf([Total
Hours per Work Order]![Month]=6,IIf([Work Order by
Activity_Quantity]![Activity Quantity]>1,(1*[Activity Type Index
Static Table]![June Index])+([Work Order by
Activity_Quantity]![Activity Quantity]-1)*[Activity Type Index Static
Table]![June Index]*[Activity Type Index Static Table]![Secondary
Mutiplier],[Activity Type Index Static Table]![June
Index]),(IIf([Total Hours per Work Order]![Month]=7,IIf([Work Order by
Activity_Quantity]![Activity Quantity]>1,(1*[Activity Type Index
Static Table]![July Index])+([Work Order by
Activity_Quantity]![Activity Quantity]-1)*[Activity Type Index Static
Table]![July Index]*[Activity Type Index Static Table]![Secondary
Mutiplier],[Activity Type Index Static Table]![July
Index]),0))))))))))))))) AS [Total Index Points]
FROM [Total Hours per Work Order] INNER JOIN ([Work Order by
Activity_Quantity] INNER JOIN [Activity Type Index Static Table] ON
[Work Order by Activity_Quantity].Activity = [Activity Type Index
Static Table].[Activity Number]) ON [Total Hours per Work Order].WONUM
= [Work Order by Activity_Quantity].WONUM
GROUP BY [Work Order by Activity_Quantity].WONUM, [Total Hours per
Work Order].[Total Hrs per WO];

I am attempting to find what month work order and activity are from
and then grab that month's index number and calculate the amount of
index points (from a static table) a given order should have per
month. The equation is taking the static table index number and
multiplying it by the total hours per activity per work order (from a
query). I was wondering if there was a way to complete this in VB.

Any help will be appreciated!
Thanks
Nov 13 '05 #1
4 2001
"ED" <da******@hotmail.com> wrote in message
news:ad**************************@posting.google.c om...
I am attempting to to write a query that has a numerous nested IIf
statements. The problem that I am having is that it is to long of a
query to be built in design mode and when I build it in sql mode after
a certain point it give me the error message that the expression is to
complex. Below is the sql code that I am using (this works so far,
anything added to the code will give me the to complex error message.)

I am attempting to find what month work order and activity are from
and then grab that month's index number and calculate the amount of
index points (from a static table) a given order should have per
month. The equation is taking the static table index number and
multiplying it by the total hours per activity per work order (from a
query). I was wondering if there was a way to complete this in VB.


Use the switch() function instead of IIf()
Nov 13 '05 #2

I understand how to use the switch to determine what month that it is
but I will still have to use the IIF in order to calculate how many
index points are needed. After I determine the month I need to
determine the quantity and if it is greater than one. If it is greater
than one I need to multiply the first quantity by the index and then add
the remaining quantity to a mutiplier and then to the index. I dont
know how I will be able to complete this in one query or if I need to
try to break up the query into further steps.

The equation is as follows:

if month = 1, then
if quantity > 1, then
1*jan index + (quantity - 1) * (jan index*multiplier)
else jan index
if month = 2 repeat for all months

month is being brought in by a query, but it is stored in table

quantity is being brought in from a table

index and multiplier brought in from a static table

I hope that this explains what I am trying to do better.

Thanks

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3
"Ernie DAmato" <da******@hotmail.com> wrote in message
news:40**********************@news.newsgroups.ws.. .

I understand how to use the switch to determine what month that it is
but I will still have to use the IIF in order to calculate how many
index points are needed. After I determine the month I need to
determine the quantity and if it is greater than one. If it is greater
than one I need to multiply the first quantity by the index and then add
the remaining quantity to a mutiplier and then to the index. I dont
know how I will be able to complete this in one query or if I need to
try to break up the query into further steps.

The equation is as follows:

if month = 1, then
if quantity > 1, then
1*jan index + (quantity - 1) * (jan index*multiplier)
else jan index
if month = 2 repeat for all months

month is being brought in by a query, but it is stored in table

quantity is being brought in from a table

index and multiplier brought in from a static table

I hope that this explains what I am trying to do better.

sql server's case statement is really what you need here - a shame that Jet
never introduced it. Oh well. One suggestion I have is to make a derived
table to produce the indexes, so the query would look something like this
select IIf(q.quantity>1, 1* A.idx + (q.quantity - 1) * (A.idx*m.multiplier),
A.idx)
from
(
select <keycolumn>,
Switch
(
[month] = 1, jan_index,
[month] = 2, feb_index
.....
[month] = 12, dec_index
) as idx
) as A

inner join <rest of tables go here>

I'm not sure if you follow this logic. But, I also suspect there is a much
better, simpler way to do this. Twelve case statements, one for each month
sounds like a bad design or bad query logic or both. Post your table
structures with some sample data if you need more help.






Nov 13 '05 #4
ED
I understand how to use the switch to determine what month that it is
but I will still have to use the IIF in order to calculate how many
index points are needed. After I determine the month I need to
determine the quantity and if it is greater than one. If it is greater
than one I need to multiply the first quantity by the index and then add
the remaining quantity to a mutiplier and then to the index. I dont
know how I will be able to complete this in one query or if I need to
try to break up the query into further steps.

The equation is as follows:

if month = 1, then
if quantity > 1, then
1*jan index + (quantity - 1) * (jan index*multiplier)
else jan index
if month = 2 repeat for all months

month is being brought in by a query, but it is stored in table

quantity is being brought in from a table

index and multiplier brought in from a static table

I hope that this explains what I am trying to do better.

Thanks
Nov 13 '05 #5

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

Similar topics

4
by: Starbuck | last post by:
OK, first let me say that I am no DB person. But I have a user here who keeps getting this error whenever she does, whatever it is she does, with databases... A google search takes me to...
2
by: Mikel | last post by:
I am trying to get around the problem "The expression you have entered is too complex" for a select query. (The example below is not the expression that is giving me headaches.) So I am thinking...
8
by: Matt | last post by:
Hi all, Thank you for taking the time. I have a database with 45 tables on it. 44 tables are linked to a main table through a one to one relationship. My question is, is there no way i can...
2
by: Ben de Vette | last post by:
Hi, I'm using the querybuilder when updating a record in a table (Access). However, I get a "Query is too complex" message. The Primary key is autonumbered. Why is it making such a complex...
1
by: arun | last post by:
Query is too complex -------------------------------------------------------------------------------- Hi, I was trying to solve this problem since last two days but couldn't find any solution. ...
1
by: Randy Volkart | last post by:
I'm trying to fix a glitch in a complex access database, and have a fairly complex problem... unless there's some obscure easy fix I don't know being fairly new with Access. Basically, the area...
19
by: kawaks40 | last post by:
Hi everyone :) I just recently started using access/sql. and right away I ran into this problem "SQL expression too complex" I google'd a lot on what it means, and the only workaround I've...
3
by: Eric Davidson | last post by:
DB2 9.5 I keep geting the message. SQL0101N The statement is too long or too complex. SQLSTATE=54001 When one of my sql statements takes over 60 seconds to compile the sql statement. Is...
0
crystal2005
by: crystal2005 | last post by:
Hi, I am having trouble with some complex SQL queries. I’ve got winestore database, taken from Web Database Application with PHP and MySQL book. And some question about queries as the following ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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,...

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.