We help IT Professionals succeed at work.

Access query error

Michele Kihiu
on
136 Views
Last Modified: 2017-04-16
I've built the following query in MS Access:

SELECT
 f.Beneficiary_ID,
 FA_Amount,
 f.Created_time,
 t.Beneficiary_ID,
 t.Amount, [Request TIME]
FROM (Fund_Allocation AS f INNER JOIN Transactions AS t ON f.Beneficiary_ID = t.Beneficiary_ID)
INNER JOIN
(SELECT
  ff.Beneficiary_ID,
  MAX(Created_time) AS Createdtime,
  MAX([Request TIME]) AS Request_time,
  DateDiff("d", Created_time, Request_time) AS DaysDiff
 FROM Fund_Allocation AS ff
  INNER JOIN Transactions AS tt
  ON ff.Beneficiary_ID = tt.Beneficiary_ID
  GROUP BY ff.Beneficiary_ID, DaysDiff
  HAVING DaysDiff > 60)  AS FA2
ON (f.Beneficiary_ID = FA2.Beneficiary_ID)
AND (f.Created_time = FA2.Createdtime);

I'm getting the error:
Your query does not include the specified expression 'DateDiff("d",Created_time,Request_time)' as part of an aggregate function.
Comment
Watch Question

Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Michele KihiuSenior Software Engineer

Author

Commented:
Thanks for your clear and detailed explanation, Joe!
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
You are welcome .
Believe it or not, back in March ... at work my group took a 5 day SQL Server Class.
When we got to Group By / Aggregate queries, the instructor laid out this rules ... in a manner that I have not seen in 24+ years of working with Access, lol.

You'll find the following helpful as well:

-- SQL SERVER PROCESSING ORDER --
1. FROM  
2. WHERE  
3. GROUP BY
4. HAVING
5. SELECT
6. ORDER BY

-- SQL WRITTEN ORDER --
5. SELECT
1. FROM
2. WHERE
3. GROUP BY
4. HAVING
6. ORDER BY

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.