Each group by expression must contain at least one column that is not an outer reference

I have an append query that generates the following error message:

ODBC--call failed.
[Microsoft][ODBC SQL Server Driver][SQL Server] Each group by expression must contain at least one column that is not an outer reference. (#164)

I am sure that this query worked at one time, but now I am getting the error message.

Does anyone have an idea how I can get around this problem?
INSERT INTO tblTempPSPHeader ( PSPReferralId, CheckAmount, CheckDate )
SELECT tblTempPSPDetail.PSPReferralId, Sum(tblTempPSPDetail.AmountToPay) AS SumOfAmountToPay, Date() AS Expr1
FROM tblTempPSPDetail
GROUP BY tblTempPSPDetail.PSPReferralId, Date();

Open in new window

LVL 3
Douglas CummingsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbizupCommented:
The error is being caused by the Date() function in your Group By clause.

It also occurs if you use constants in your Group By clause.

Try removing Date() from your Group By clause, but leave it in the SELECT:

INSERT INTO tblTempPSPHeader ( PSPReferralId, CheckAmount, CheckDate )
SELECT tblTempPSPDetail.PSPReferralId, Sum(tblTempPSPDetail.AmountToPay) AS SumOfAmountToPay, Date() AS Expr1
FROM tblTempPSPDetail
GROUP BY tblTempPSPDetail.PSPReferralId

Open in new window



As an aside, is Date (today's date) what you mean to insert, or are you trying to refer to a column named Date?

If you want to use a column named Date, try this:

INSERT INTO tblTempPSPHeader ( PSPReferralId, CheckAmount, CheckDate )
SELECT tblTempPSPDetail.PSPReferralId, Sum(tblTempPSPDetail.AmountToPay) AS SumOfAmountToPay, [Date]
FROM tblTempPSPDetail
GROUP BY tblTempPSPDetail.PSPReferralId, [Date]

Open in new window



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeffrey CoachmanMIS LiasonCommented:
Does this run on it's own and return the correct daytaset:

SELECT tblTempPSPDetail.PSPReferralId, Sum(tblTempPSPDetail.AmountToPay) AS SumOfAmountToPay, Date() AS Expr1
FROM tblTempPSPDetail
GROUP BY tblTempPSPDetail.PSPReferralId, Date();
Douglas CummingsAuthor Commented:
Thanks for the help! Worked kike a charm. It was today's date that I wanted to insert into the CheckDate field.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

mbizupCommented:
Glad to help out!

You mentioned that this had worked for you in the past.  Just curious - Have you made a switch from Access to SQL for your back end?

To my knowledge, your syntax would have worked for you previously if you had been using an Access back end.
Douglas CummingsAuthor Commented:
Originally the temporary tables were local. But, due to other factors, I had to use a SQL database instead. That is when the problem developed.

Thanks again.
Douglas CummingsAuthor Commented:
I actually resolved the issue on my own, but not quite as elegantly as you. I figured it was the Date() expression and I simply deleted it from the query and added the date to the records via an update query. I like your solution better as it saved me a step.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.