473,770 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL expression too complex

11 New Member
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 seen sofar,
is to just rewrite my code/query.

Situation:
I am sorting forms into the way they are used (print,storage, readonly,etc... ).
However there are 20 different ways a form can be used,
so my initial approach was to write one big IFF statement,
sorting out each case.

however, around 11 or so IFF statements, I started to get this error,
so i was wondering if anyone had any ideas on how to make this sorting easier/workable.


Code:
This is what my huge IFF statement looks like:

If query <> "" Then

query = query & ",iif(mq.ffileu sage=" & Chr(34) & "0" & Chr(34) & "," & Chr(34) & "View Only" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "~0" & Chr(34) & "," & Chr(34) & "View Only" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "1" & Chr(34) & "," & Chr(34) & "View and Print" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "~1" & Chr(34) & "," & Chr(34) & "View and Print" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "~1~2" & Chr(34) & "," & Chr(34) & "View and Print and Fill and Print" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "2" & Chr(34) & "," & Chr(34) & "Fill and Print" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "~2" & Chr(34) & "," & Chr(34) & "Fill and Print" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "3" & Chr(34) & "," & Chr(34) & "Fill and Print and Submit" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "2~3" & Chr(34) & "," & Chr(34) & "Fill and Print and Submit" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "4" & Chr(34) & "," & Chr(34) & "Print and Fill and Mail" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "5" & Chr(34) & "," & Chr(34) & "Fill Print Save" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "H" & Chr(34) & "," & Chr(34) & "Paper Copy" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "~H" & Chr(34) & "," & Chr(34) & "Paper Copy" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "S" & Chr(34) & "," & Chr(34) & "Source Application" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "~H~0" & Chr(34) & "," & Chr(34) & "xxxxxxx" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "~H~1" & Chr(34) & "," & Chr(34) & "xxxxxx" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "~H~2" & Chr(34) & "," & Chr(34) & "xxxxx" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "H~1" & Chr(34) & "," & Chr(34) & "xxxx" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "H~2~1" & Chr(34) & "," & Chr(34) & "xxx" & Chr(34) _
& ",iif(mq.ffileu sage=" & Chr(34) & "H~1~4" & Chr(34) & "," & Chr(34) & "xx" & Chr(34) _
& "," & Chr(34) & "" & Chr(34) & ")))))))))))))) )))))) as [Attatchment Usage]"

**basically, all im doing is checking the table for various values (form uses),
and when it outputs the form use in excel it will label it accordingly.
** ie. if the value read is "0" then it will output "View Only" in the excel document

I know the code works, because if I limit the amount of IFF statements to 12, it will work fine.
But as soon as I add anymore, it will give me the "too complex" error.


Anyone have an idea of how I could make this simplier?
I was thinking maybe a CASE function or something,
but I'm not sure, because I've only started sql a few days ago.


Thanks for your help :)
k,40
Aug 3 '07
19 3644
FishVal
2,653 Recognized Expert Specialist
ok, sorry I am confused
When I write either the CASE/Switch function, how do I get the output in excel to be all in a column called [File Usage].


I cannot figure out where to put the "AS" part of the code.



Also, if I make a public function for the CASE statement,
how do I reference it??


Thanks,
k40
Replace nested IIf's with Switch function in your query SQL expression. For Switch function syntax see Access help.
Aug 7 '07 #11
puppydogbuddy
1,923 Recognized Expert Top Contributor
ok, sorry I am confused
When I write either the CASE/Switch function, how do I get the output in excel to be all in a column called [File Usage].


I cannot figure out where to put the "AS" part of the code.



Also, if I make a public function for the CASE statement,
how do I reference it??


Thanks,
k40
<<<<When I write either the CASE/Switch function, how do I get the output in excel to be all in a column called [File Usage].>>>>
In the sample you provided, you used ffileusage...if it should be [File Usage], then replace ffileusage with [File Usage] in the code I provided.

<<<<<Also, if I make a public function for the CASE statement,
how do I reference it??>>>

in VBA code>>>>MyCrite ria
in the criteria row of a query grid>>>>MyCrite ria()
Aug 7 '07 #12
kawaks40
11 New Member
:) ok, that helped a lot
Now it sorts properly... except one minor detail.

I am now getting the error
"Repository Report Generator was unable to append all the data to the table"

- it ways that 6280 record(s) were deleted, and 0 record(s) were lost
*If data was deleted, the data you pasted or imported doesn't match
the field data type or the FieldSize property in the destination table.


My code looks like this:

The main query in the form is:

If q_attfileusage < 0 And variableInfo.Va lue = 1 Then
If query <> "" Then
query = query & ",FileUsage(mq. ffileusage) as [Atth Usage]"



Then I made a module, and made a public function ilke this:

Public Function FileUsage(ffile usage As String)
Select Case ffileusage
Case Is = "0"
FileUsage = "View Only"
Case Is = "~0"
FileUsage = "View Only"
Case Is = "1"
FileUsage = "View and Print"
Case Is = "~1"
FileUsage = "View and Print"
Case Is = "~1~2"
FileUsage = "View and Print, Fill and Print"
Case Is = "2"
FileUsage = "Fill and Print"
Case Is = "~2"
FileUsage = "Fill and Print"
Case Is = "3"
FileUsage = "Fill, Print and Submit"
Case Is = "2~3"
FileUsage = "Fill, Print and Submit"
Case Is = "4"
FileUsage = "Print Fill and Mail"
Case Is = "5"
FileUsage = "Fill, Print and Save"
Case Is = "H"
FileUsage = "Paper Copy"
Case Is = "~H"
FileUsage = "Paper Copy"
Case Is = "~H~0"
FileUsage = "Paper Copy, View Only"
Case Is = "~H~1"
FileUsage = "Paper Copy, View and Print"
Case Is = "~H~2"
FileUsage = "Paper Copy, Fill and Print"
Case Is = "H~1"
FileUsage = "Paper Copy, View and Print"
Case Is = "H~2~1"
FileUsage = "Paper Copy, View, Fill and Print"
Case Is = "H~1~4"
FileUsage = "Print, Fill and Mail"
Case Is = "S"
FileUsage = "Source Application"
Case Else
FileUsage = " - "
End Select
End Function




When I run it, it seems to work,
except there are a number of forms it lists with no "file usage" status at all
(just blank)
But there are also a number of forms that it lists correctly.


So I am unsre if it something to do with my coding.
Or is it becase the database that I am working with is incomplete

(from what I googled, I found that this may be due to the fact that
there are a number of records with unacceptable input or empty)


thanks again for all the help,
and patience ;p

k,40
Aug 7 '07 #13
kawaks40
11 New Member
the only thing I can think of is in:

Public Function FileUsage(ffile usage As String)

ffileusage >> is that right?
That is supposed to refer to an external piece of information.
I think it should be mq.ffileusage (like the IFF statements refered to)
*But I get an error everytime I try to replace it.


or, it could be in

query = query & ",FileUsage(mq. ffileusage) as [Atth Usage]"
I am trying to pass mq.ffileusage into my function.




.... so I think I am telling the query to search the wrong location.
Aug 7 '07 #14
FishVal
2,653 Recognized Expert Specialist
:) ok, that helped a lot
Now it sorts properly... except one minor detail.

I am now getting the error
"Repository Report Generator was unable to append all the data to the table"

- it ways that 6280 record(s) were deleted, and 0 record(s) were lost
*If data was deleted, the data you pasted or imported doesn't match
the field data type or the FieldSize property in the destination table.


My code looks like this:

The main query in the form is:

If q_attfileusage < 0 And variableInfo.Va lue = 1 Then
If query <> "" Then
query = query & ",FileUsage(mq. ffileusage) as [Atth Usage]"



Then I made a module, and made a public function ilke this:

Public Function FileUsage(ffile usage As String)
Select Case ffileusage
Case Is = "0"
FileUsage = "View Only"
Case Is = "~0"
FileUsage = "View Only"
Case Is = "1"
FileUsage = "View and Print"
Case Is = "~1"
FileUsage = "View and Print"
Case Is = "~1~2"
FileUsage = "View and Print, Fill and Print"
Case Is = "2"
FileUsage = "Fill and Print"
Case Is = "~2"
FileUsage = "Fill and Print"
Case Is = "3"
FileUsage = "Fill, Print and Submit"
Case Is = "2~3"
FileUsage = "Fill, Print and Submit"
Case Is = "4"
FileUsage = "Print Fill and Mail"
Case Is = "5"
FileUsage = "Fill, Print and Save"
Case Is = "H"
FileUsage = "Paper Copy"
Case Is = "~H"
FileUsage = "Paper Copy"
Case Is = "~H~0"
FileUsage = "Paper Copy, View Only"
Case Is = "~H~1"
FileUsage = "Paper Copy, View and Print"
Case Is = "~H~2"
FileUsage = "Paper Copy, Fill and Print"
Case Is = "H~1"
FileUsage = "Paper Copy, View and Print"
Case Is = "H~2~1"
FileUsage = "Paper Copy, View, Fill and Print"
Case Is = "H~1~4"
FileUsage = "Print, Fill and Mail"
Case Is = "S"
FileUsage = "Source Application"
Case Else
FileUsage = " - "
End Select
End Function




When I run it, it seems to work,
except there are a number of forms it lists with no "file usage" status at all
(just blank)
But there are also a number of forms that it lists correctly.


So I am unsre if it something to do with my coding.
Or is it becase the database that I am working with is incomplete

(from what I googled, I found that this may be due to the fact that
there are a number of records with unacceptable input or empty)


thanks again for all the help,
and patience ;p

k,40
Hi, there.

I think that the most natural, flexible and suitable solution would be the following.

Create additional table
tblSignatureCon version
txtSignature Text
txtConversion Text

and fill it with you values, e.g.
txtSignature txtConversion
0 ViewOnly
~0 ViewOnly
1 View and Print
~1 View and Print
.....
and so on

then use tables join to replace value in original table with correspondent text

Expand|Select|Wrap|Line Numbers
  1. SELECT *, tblSignatureConversion.txtConversion FROM mq JOIN tblSignatureConversion ON mq.ffileusage=tblSignatureConversion.txtSignature;
  2.  
P.S. BTW join query runs faster than that with VBA function in WHERE clause.
Aug 7 '07 #15
puppydogbuddy
1,923 Recognized Expert Top Contributor
:) ok, that helped a lot
Now it sorts properly... except one minor detail.

I am now getting the error
"Repository Report Generator was unable to append all the data to the table"

- it ways that 6280 record(s) were deleted, and 0 record(s) were lost
*If data was deleted, the data you pasted or imported doesn't match
the field data type or the FieldSize property in the destination table.


My code looks like this:

The main query in the form is:

If q_attfileusage < 0 And variableInfo.Va lue = 1 Then
If query <> "" Then
query = query & ",FileUsage(mq. ffileusage) as [Atth Usage]"



Then I made a module, and made a public function ilke this:

Public Function FileUsage(ffile usage As String)
Select Case ffileusage
Case Is = "0"
FileUsage = "View Only"
Case Is = "~0"
FileUsage = "View Only"
Case Is = "1"
FileUsage = "View and Print"
Case Is = "~1"
FileUsage = "View and Print"
Case Is = "~1~2"
FileUsage = "View and Print, Fill and Print"
Case Is = "2"
FileUsage = "Fill and Print"
Case Is = "~2"
FileUsage = "Fill and Print"
Case Is = "3"
FileUsage = "Fill, Print and Submit"
Case Is = "2~3"
FileUsage = "Fill, Print and Submit"
Case Is = "4"
FileUsage = "Print Fill and Mail"
Case Is = "5"
FileUsage = "Fill, Print and Save"
Case Is = "H"
FileUsage = "Paper Copy"
Case Is = "~H"
FileUsage = "Paper Copy"
Case Is = "~H~0"
FileUsage = "Paper Copy, View Only"
Case Is = "~H~1"
FileUsage = "Paper Copy, View and Print"
Case Is = "~H~2"
FileUsage = "Paper Copy, Fill and Print"
Case Is = "H~1"
FileUsage = "Paper Copy, View and Print"
Case Is = "H~2~1"
FileUsage = "Paper Copy, View, Fill and Print"
Case Is = "H~1~4"
FileUsage = "Print, Fill and Mail"
Case Is = "S"
FileUsage = "Source Application"
Case Else
FileUsage = " - "
End Select
End Function




When I run it, it seems to work,
except there are a number of forms it lists with no "file usage" status at all
(just blank)
But there are also a number of forms that it lists correctly.


So I am unsre if it something to do with my coding.
Or is it becase the database that I am working with is incomplete

(from what I googled, I found that this may be due to the fact that
there are a number of records with unacceptable input or empty)


thanks again for all the help,
and patience ;p

k,40
1. change: If query <> "" Then
to: If query <> "" And query Is Not Null Then

2. mq.ffileusage vs ffileusage????
query = query & ",FileUsage(mq. ffileusage) as [Atth Usage]"
vs, Public Function FileUsage(ffile usage As String)
Aug 7 '07 #16
kawaks40
11 New Member
hey guys, very sorry about this...

I think I am giving the query the wrong location.
I am using an existing database so I was using mq.ffileattatch ement based on the fact that all other queries were using that same style.
*but once I looked over the records it was returning
I realized that some records were not found on the table I thought it was looking at.
*and also, there are no blank fields in the table at all.
They are all filled with the appropriate case variables (0,~0,1,~1,etc. .)
(so there should not be any blank returns at all)



Without looking at my previous code/description,,,
if I had a database with a table called FORMS_ATTACHMEN T

and in that table I wanted to look at the column named "FILEUSAGE"

what would be the right way?



I have no idea actually what 'mq.ffileattatc hment' is pointing to,
I tried to trace it back so I could see what records are coming up as blank.
Other queries seem to work fine with it, so I used the same format of 'mq'.



thanks again :)
Aug 7 '07 #17
kawaks40
11 New Member
ok, fixed... ignore that last post :P
(the external value should not be declared as a string - in the public function)


thanks so much for the help, I really appreciate it.
I learned a lot from this.


the only thing I am working on now,
is that when I try to narrow my search to just "View Only" for example.

It will return all results that were
- null
- View Only
- Paper Copy + View Only



but thank you very very much for the help!
I am happy just being able to fix the 'too complex' problem

thanks,
k40
Aug 7 '07 #18
puppydogbuddy
1,923 Recognized Expert Top Contributor
ok, fixed... ignore that last post :P
(the external value should not be declared as a string - in the public function)


thanks so much for the help, I really appreciate it.
I learned a lot from this.


the only thing I am working on now,
is that when I try to narrow my search to just "View Only" for example.

It will return all results that were
- null
- View Only
- Paper Copy + View Only



but thank you very very much for the help!
I am happy just being able to fix the 'too complex' problem

thanks,
k40
1. what did you declare external value as??

2. What is ~0 vs 0 ??
Public Function FileUsage(ffile usage As String)
Select Case ffileusage
Case Is = "0" <<<<<<<<<<<<<<< <<<<<<<<
FileUsage = "View Only"
Case Is = "~0" <<<<<<<<<<<<<<< <<<<<<<<????
FileUsage = "View Only"
Aug 7 '07 #19
kawaks40
11 New Member
HI :)


1. I didn't declare the type of value being inputted.
I just left it as "ffileusage " (not - ffileusage as String)


2. 0 and ~0 aren't operators/functions...
they're just inputted to determine the usage of the files that I am sorting.
so:
0 indicates 'read only'
~0 indicates 'read only and print'








:) thanks for all the help,again
Aug 15 '07 #20

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

Similar topics

0
1732
by: Christos TZOTZIOY Georgiou | last post by:
Hi all, this post contains at the end a handy module that I've used quite often when I wanted to analyse the occasional complex expression and how it was to be evaluated. The function analyse_expression is called with a single string argument containing an expression. Names are allowed (actually, preferred over numbers ;-), since the function eval's in a protected dictionary, where names are generated as needed.
39
7888
by: | last post by:
I am trying to run the following agregate function in a parameterized query on Access2000: Min(.*sqr(./.)/) The query saved OK, but an attempt to run it results in the message: The expression is typed incorrectly or it is too complex to be evaluated If the sintax correct? Perhaps it is, otherwise it would not save. What can be done about it?
3
2029
by: Tom | last post by:
I have struggled with the issue of whether or not to use Regular Expressions for a long time now, and after implementing many text manipulating solutions both ways, I've found that writing specialized code instead of an RE is almost always the better solution. Here is why.... RE's are complex. Sure it is one line of code, but it is on hell of a line. Some of my RE remind me of the obfuscated code contest winners, where one line of...
5
2245
by: Bob Stearns | last post by:
Is there an easy way (without duplication of the complex expression) to use the same complex expression in all three places? Will something like this work? WITH (SELECT t.*, <complex expr> AS x FROM <base_table> AS t) AS wt SELECT * FROM wt WHERE ABS(x)<10 ORDER BY ABS(x)
2
6077
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 that I just need to do the parsing and calculating in an event procedure for an "On Click" event. My question is: If I have a query field in access97 that parses date (in format
1
3678
by: Andrew | last post by:
How can I create a property or function for a typed datasets column? By this I need to add a new column (element) to the table or override an existing column. For instance I have an Invoice table that needs to have a Status property. This status property has to read the other elements in the table to determine what the status is and return a string. I know that I can enter this in the expression fields, but as the expressions become more...
28
16423
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to write a safe but easy implementation (i.e. no codedom) for an IBindingListView.Filter (by compiling to a Predicate<T>). Anybody know if this is possible at all? Marc
9
2139
by: jessicaeatworld | last post by:
Hi, I'm using Access 2003 on Windows XP. My Error: This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables. I'm guessing that one of these calcs is the problem: (/)*31 AS , (/)*31 AS , (/)*31 AS , / AS
18
7975
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp defintion of "expression" and "statement"? What is the difference between an expression and a statement?
1
5026
by: Coll | last post by:
I'm receiving this message when running a query... This expression is typed incorrectly or is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables. Here's the background. I have a query. I've figured out through cutting and pasting which field is the culprit. So I have a field with the following info...
0
9595
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9432
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10059
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10008
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9873
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.