SQL error 3122

dogdays

Active Member
Joined
Apr 28, 2008
Messages
434
Office Version
  1. 2007
Win 732, Access 2003
I have an SQL statement that when I try to execute it returns error 3122. You tried to execute a query that does not include the specified expression 'nHouseholdNumber' as part of an aggregate function. The statement is :
Code:
SELECT nHouseholdNumber, nIndividualNumber, dtDateEntered,  tSolicitor, tAcknowledgedBy, SUM(cAmount) as 'cTotalAmount'  FROM tblFiscalGifts WHERE nIdentity > 0  AND (dtDateEntered >= #8/3/2011# AND dtDateEntered <= #10/03/2011#) GROUP BY nIndividualNumber

Any advice is appreciated.

Jack
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I run across this error many times when you are doing a group by and you leave out a field.

Fix would be:
Code:
SELECT nHouseholdNumber, nIndividualNumber, dtDateEntered,  tSolicitor, tAcknowledgedBy, SUM(cAmount) as 'cTotalAmount'  
FROM tblFiscalGifts
 WHERE nIdentity > 0  AND (dtDateEntered >= #8/3/2011# AND dtDateEntered <= #10/03/2011#) 
GROUP BY nHouseholdNumber, nIndividualNumber
 
Last edited:
Upvote 0
Thx psycoperl. Does this mean that the GROUP BY fields have to be the first column names after the SELECT statement, in order?

Jack
 
Upvote 0
hi, Jack

I understand the order of the fields doesn't matter. Basically, for every selected field without a SUM or MAX or MIN or COUNT or whatever repeats in the GROUP BY clause.

regards

Code:
SELECT some_field, another_field, and_one_more, SUM(whatever)
FROM table
WHERE some_field = 'optional_filter_value'
GROUP BY some_field, another_field, and_one_more
HAVING SUM(whatever)>10000

I've added a WHERE clause to show how to filter the dataset before the aggregate function (SUM in the example) and also a HAVING clause which goes after the GROUP BY and applies to the aggregated result.
 
Upvote 0
Fazza:
Thanks for the information, especially the HAVING clause.

Jack
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top