Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Too complex expression

Status
Not open for further replies.

honeypot3

Instructor
Feb 8, 2005
77
GB
Hi there

I wonder if you can help me, the following SQL works with no trouble at all:

SELECT Trade.Trade, CDate([year] & "-" & [month] & "-01") AS CalcDate, (Avg([Resp])*8)/80 AS [Percent]
FROM (Trade INNER JOIN ContractorDetails ON Trade.TradeID = ContractorDetails.TradeID) INNER JOIN ContJobQueResMonYearLink ON ContractorDetails.[Contractor ID] = ContJobQueResMonYearLink.CoID
GROUP BY Trade.Trade, CDate([year] & "-" & [month] & "-01")
HAVING (((CDate([year] & "-" & [month] & "-01"))>=CDate([forms]![dateselect3]![year] & "-" & [forms]![dateselect3]![month] & "-01") And (CDate([year] & "-" & [month] & "-01"))<=CDate([forms]![dateselect3]![toyear] & "-" & [forms]![dateselect3]![tomonth] & "-01")))
ORDER BY Trade.Trade;


But when I try to extend this to include another field which belongs in another query called PartnershipName Access tells me that the expression is too complex (please see below) - any ideas why?

SELECT [NewExcelOutputPartner contract subquery].[Partnership Name], Trade.Trade, CDate([year] & "-" & [month] & "-01") AS CalcDate, Avg([resp])*8/80 AS [Percentage Average]
FROM ([NewExcelOutputPartner contract subquery] INNER JOIN ContractorDetails ON [NewExcelOutputPartner contract subquery].CoID=ContractorDetails.[Contractor ID]) INNER JOIN Trade ON ContractorDetails.TradeID=Trade.TradeID
GROUP BY [NewExcelOutputPartner contract subquery].[Partnership Name], Trade.Trade, CDate([year] & "-" & [month] & "-01")
HAVING (((CDate([year] & "-" & [month] & "-01"))>=CDate(forms!dateselect3!year & "-" & forms!dateselect3!month & "-01") And (CDate([year] & "-" & [month] & "-01"))<=CDate(forms!dateselect3!toyear & "-" & forms!dateselect3!tomonth & "-01")))
ORDER BY [NewExcelOutputPartner contract subquery].[Partnership Name], Trade.Trade;


 
maybe because the query is too complex, there's only a certain number of tables you can call in a query, and referencing another subquery doesn't count as 1 table, rather it counts as all the tables referenced in the subquery.

--------------------
Procrastinate Now!
 
I don't think it is the number of tables/queries as it works fine if you just remove "))>=CDate(forms!dateselect3!year & "-" & forms!dateselect3!month & "-01") And (CDate([year] & "-" & [month] & "-01"))<=CDate(forms!dateselect3!toyear & "-" & forms!dateselect3!tomonth & "-01")))

It seems to be that once you try to run the query where you are setting the criteria of selecting the date range that the query struggles - it works fine with all the tables/queries and Cdate initial field but falls over when it is asked to look at the entries on the form DateSelect3.

Any other ideas?
 
you don't want that in a HAVING clause anyway, move it to a WHERE clause.

may not solve your problem, but it's the correct syntax.


Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases: The Fundamentals of Relational Database Design
 
Solved it - got the smaller version of the query to make a table of its own first then ran the form selection criteria separtely - thanks for your efforts though
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top