Results 1 to 10 of 10
  1. #1
    kaledev is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    20

    Question Query too complex error

    I noticed a strange problem with a query I am trying to contruct. I have a Union query that runs perfectly fine...however if I made a second query that uses it, everything returns a "Query too complex error". So let me try to explain... The first query is below.

    "Q01 Generate Data With Duplicates":



    Code:
    SELECT Format([dbo_OLDDATA].[Report Dt],"yyyy-mm-dd") as [Report Dt], [dbo_OLDDATA].[Report Tm], [dbo_OLDDATA].Controller, [dbo_OLDDATA].[Eq Init], [dbo_OLDDATA].[Equip Nr], [dbo_OLDDATA].[Dwell Start Dt], [dbo_OLDDATA].[Dwell Start Tm], [dbo_OLDDATA].[Dwell Start Event], [dbo_OLDDATA].[Dwell Days], [dbo_OLDDATA].Terminal, [dbo_OLDDATA].[Wb Origin], [dbo_OLDDATA].[Wb Destination], [dbo_OLDDATA].[Wb Route]
    FROM [dbo_OLDDATA]
    WHERE ((([dbo_OLDDATA].[Report Dt]) Between CDate([Forms]![Main]![txtReportStartDate]) And CDate([Forms]![Main]![txtReportEndDate]))) AND [Q01 Generate Data with Duplicates].[Controller] = [Controller];
    UNION ALL SELECT [MISSED_DATES].[Missed date] AS [Report Dt], [dbo_OLDDATA].[Report Tm], [dbo_OLDDATA].Controller, [dbo_OLDDATA].[Eq Init], [dbo_OLDDATA].[Equip Nr], [dbo_OLDDATA].[Dwell Start Dt], [dbo_OLDDATA].[Dwell Start Tm], [dbo_OLDDATA].[Dwell Start Event], [dbo_OLDDATA].[Dwell Days], [dbo_OLDDATA].Terminal, [dbo_OLDDATA].[Wb Origin], [dbo_OLDDATA].[Wb Destination], [dbo_OLDDATA].[Wb Route]
    FROM [MISSED_DATES] INNER JOIN [dbo_OLDDATA] ON [MISSED_DATES].[Duplicate From] = [dbo_OLDDATA].[Report Dt]
    WHERE ((([MISSED_DATES].[Missed date]) Between CDate([Forms]![Main]![txtReportStartDate]) And CDate([Forms]![Main]![txtReportEndDate])));
    The query above runs great....now if I create a second query as listed below. It returns the "too complex" error.

    Code:
    SELECT [Q01 Generate Data with Duplicates].[Report Dt]
    FROM [Q01 Generate Data with Duplicates];
    I have tried every field, and it returns the same error. The first SQL statement is pulling from a SQL Server DB, but like I said it works fine alone so I am not sure if that has anything to do with it. Any ideas? Thanks!

  2. #2
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    http://support.microsoft.com/kb/125767

    It looks like you're well under your limit of 16 Tables and 40 WHERE/HAVING clauses, so my guess is that you're running to the Stack Space issue.

    Unfortunately, I don't know of any way to increase the stack space of an individual program in Windows. You can try increasing the amount of Virtual Memory used or closing some programs. . .

    However, your best bet at this point is to try and rebuild a brand new Query that does what you want, instead of Querying off of your original Query

    Does the following Query work for you? If so, I'd just use it:
    Code:
    SELECT Format([dbo_OLDDATA].[Report Dt],"yyyy-mm-dd") as [Report Dt]
    FROM [dbo_OLDDATA]
    WHERE ((([dbo_OLDDATA].[Report Dt]) Between CDate([Forms]![Main]![txtReportStartDate]) And CDate([Forms]![Main]![txtReportEndDate]))) AND [Q01 Generate Data with Duplicates].[Controller] = [Controller];
    UNION ALL SELECT [MISSED_DATES].[Missed date] AS [Report Dt], [dbo_OLDDATA].[Report Tm], [dbo_OLDDATA].Controller, [dbo_OLDDATA].[Eq Init], [dbo_OLDDATA].[Equip Nr], [dbo_OLDDATA].[Dwell Start Dt], [dbo_OLDDATA].[Dwell Start Tm], [dbo_OLDDATA].[Dwell Start Event], [dbo_OLDDATA].[Dwell Days], [dbo_OLDDATA].Terminal, [dbo_OLDDATA].[Wb Origin], [dbo_OLDDATA].[Wb Destination], [dbo_OLDDATA].[Wb Route]
    FROM [MISSED_DATES] INNER JOIN [dbo_OLDDATA] ON [MISSED_DATES].[Duplicate From] = [dbo_OLDDATA].[Report Dt]
    WHERE ((([MISSED_DATES].[Missed date]) Between CDate([Forms]![Main]![txtReportStartDate]) And CDate([Forms]![Main]![txtReportEndDate])));

  3. #3
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    I'd experiment; not sure which straw is breaking the camel's back....

    Format([dbo_OLDDATA].[Report Dt],"yyyy-mm-dd") as [Report Dt]

    might temp remove that if feasible just as a sanity check.....

    the double use of [Report Dt] makes me a little uneasy, I might change to:
    Format([dbo_OLDDATA].[Report Dt],"yyyy-mm-dd") as [Report FDt]

    though that might cascade into alot of stuff and don't mean to send you on a wild goose chase....

    In another approach; your 2nd query is filtering the results of the 1st....can you reverse that and first filter your record set before the union? not sure....

    Going ugly; have you tried a 2nd query that is a simple MakeTable of the first query's record set (or Append into a premade empty local table)....then you have a local table to proceed with for more queries. This idea will make a sql jockey puke however... am only throwing out ideas - obviously you've done alot of work so far and just trying to help.

  4. #4
    kaledev is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    20
    I've tried a few different solutions and nothing has worked. The problem is that I have essentially 3 queries filtering off of the original. So I cannot imagine how I would combine them all into one. I wasn't actually trying to return 1 field as I posted, the actual query is more complicated and when it didn't work I said...ok how about just one field, can you even do that?...and the answer is no it cannot.

    The whole query is below

    Code:
    SELECT [Q01 Generate Data with Duplicates].[Report Dt], [Q01 Generate Data with Duplicates].Terminal, Count([Q01 Generate Data with Duplicates].[Eq Init]) AS [Units With Outbound Billing]
    FROM [Q01 Generate Data with Duplicates]
    WHERE ((([Q01 Generate Data with Duplicates].[Wb Origin]) Is Not Null) AND ((([Q01 Generate Data with Duplicates].[Wb Destination])<>[Terminal]) Is Not Null))
    GROUP BY [Q01 Generate Data with Duplicates].[Report Dt], [Q01 Generate Data with Duplicates].Terminal;
    Now interestingly enough....I tried to break up this query and the following partial query worked.

    "Pre-Q02":
    Code:
    SELECT *
    FROM [Q01 Generate Data with Duplicates]
    WHERE ((([Q01 Generate Data with Duplicates].[Wb Origin]) Is Not Null) AND ((([Q01 Generate Data with Duplicates].[Wb Destination])<>[Terminal]) Is Not Null));
    I then tried to create a query to filter that one the rest of the way

    Code:
    SELECT [Pre-Q02].[Report Dt], [Pre-Q02].Terminal, Count([Pre-Q02].[Eq Init]) AS [Units With Outbound Billing]
    FROM [Pre-Q02]
    GROUP BY [Pre-Q02].[Report Dt], [Pre-Q02].Terminal;
    and...."too complex". I have no clue what to do. The problems with these queries only began when I started running them off of a ODBC linked DB, they actually work fine in a previous version of the database with the table inside.

    Using a Make Table would probably not even work since I am pulling from a DB with over 3 million records...or if it did work it would take a long time. The Format isn't the issue, I actually added that to see if it would fix the problem since my dates are in a different format in SQL Server.

    I suppose it could be something with memory, but that would just seem strange...my virtual memory is twice my RAM.

  5. #5
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    upload the table please.

  6. #6
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Well, after reading up some more, it seems that "Query too complex" means nothing more than "Hey, I ran into a problem with this thing, but I don't know what the problem is!"

    This means that the problem could be anything in the Query.

    However, I do have a question about your Query's WHERE clause. You have a condition in there stating:
    Code:
    (([Q01 Generate Data with Duplicates].[Wb Destination])<>[Terminal]) Is Not Null
    Shouldn't that be something like the following instead:
    Code:
    ([Q01 Generate Data with Duplicates].[Wb Destination]<>[Terminal]) AND 
    ([Terminal] Is Not Null)

  7. #7
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    I think
    (([Q01 Generate Data with Duplicates].[Wb Destination])<>[Terminal]) Is Not Null

    is all right, just different expression of same logic result.

  8. #8
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    in the #1 post, in query "Q01 Generate Data With Duplicates", why does the name of query show in the SQL text, what is [Q01 Generate Data with Duplicates].[Controller] and what is [Controller]:

    AND [Q01 Generate Data with Duplicates].[Controller] = [Controller]; UNION ALL SELECT

  9. #9
    kaledev is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    20
    Actually that looks like a typo, ive gone through so many different versions of the same query I probably posted an old one.

    Code:
    (dbo_OLDDATA.Controller)=[SelController]
    [Controller] was just a parameter to drill down the data, it would be difficult to explain but there are around 9 or 10 "Controllers".

    Strangely enough, my last query:

    Code:
    SELECT [T_Pre-Q02].[Report Dt], [T_Pre-Q02].Terminal, Count([T_Pre-Q02].[Eq Init]) AS [Units with Outbound Billing]
    FROM [T_Pre-Q02]
    GROUP BY [T_Pre-Q02].[Report Dt], [T_Pre-Q02].Terminal;
    Works if I first append "Pre-Q02" query to a table...then run the query against the table instead of the "Pre-Q02" query. This isn't a huge deal since i've gone from around 3million records to 200 or so by this time, but definitely not ideal. I don't get the exact results I expect but I'm guessing thats user error from changing these so much...

    I can post a sample table if you think it will help, i'll just have to make it much smaller, and like i said its run from an ODBC connection which seems to have an effect on it.

  10. #10
    kaledev is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    20
    As an update I just gave up and put the data from the first query into a table and went from there. I went around in circles for days and nothing worked.

    For some reason I can make the most complicated query in the world as long as it is a select all; if I even think about selecting less than all fields it freaks out on me and calls it too complex...so no clue how to solve this problem...

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Help with complex query (for me at least)
    By GrindEspresso in forum Queries
    Replies: 5
    Last Post: 01-26-2011, 11:03 AM
  2. Complex query system for map database
    By brian.tunks in forum Queries
    Replies: 2
    Last Post: 07-28-2010, 07:07 AM
  3. Complex Query/Queries for a Report
    By Rawb in forum Queries
    Replies: 3
    Last Post: 02-04-2010, 07:44 AM
  4. Complex Update query
    By niihla10 in forum Queries
    Replies: 1
    Last Post: 08-28-2009, 01:02 PM
  5. Replies: 1
    Last Post: 07-08-2009, 03:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums