Re: DateDiff
- From: Smartin <smartin108@xxxxxxxxxxx>
- Date: Tue, 02 Jan 2007 17:38:48 -0500
Hi Joanne,
The purpose of the GROUP BY clause is to perform some sort of aggregation on some field. Your SELECT clause has no aggregation, hence the error. Alternatively, you can add the other fields from your SELECT clause to the GROUP BY clause.
I seem to recall from your earlier issue that there might be multiple rows for each employee, right? If so, then this might work:
SELECT tblOLPDays.[Employee ID], tblOLPDays.[OLP Begin Date],
tblOLPDays.[OLP End Date], DateDiff("d",[OLP Begin Date],[OLP End Date]) AS
[Total Days]
FROM tblOLPDays
WHERE (((tblOLPDays.[Type of Day])<>"carryover"))
GROUP BY tblOLPDays.[Employee ID], tblOLPDays.[OLP Begin Date],
tblOLPDays.[OLP End Date], DateDiff("d",[OLP Begin Date],[OLP End Date])
ORDER BY tblOLPDays.[Employee ID];
If not, could you post a few lines of sample data and the result you are looking for?
Joanne wrote:
Hello,
Here is the query:
SELECT tblOLPDays.[Employee ID], tblOLPDays.[OLP Begin Date], tblOLPDays.[OLP End Date], DateDiff("d",[OLP Begin Date],[OLP End Date]) AS [Total Days]
FROM tblOLPDays
WHERE (((tblOLPDays.[Type of Day])<>"carryover"))
GROUP BY tblOLPDays.[Employee ID];
When I take out the group by Employee id, the query runs fine. But I would like to have each employee listed separately. Isn't that possible with this query? Thank you.
"Bruce Meneghin" wrote:
Can you list the whole query? you get this message when you have a GROUP BY clause in the query done incorrectly.
"Joanne" wrote:
Hello,
I have set up a query that runs against a table where I've listed vacation time for each employee. The query contains a new field with the following expression:
Total Days: DateDiff("d",[OLP Begin Date],[OLP End Date]) I have also included from my table, the fields Employee ID (group by), OLP Begin Date and OLP end date. OLP begin and end dates are formatted as dates. When I run the query, I get the following error
"You tried to execute a query that does not include the specified expression 'OLP Begin Date' as part of an aggregate function. I have been getting a lot of assistance from Smartin on setting up this database. I hesitate to yet again ask him a stupid question, so I am posting this to anyone who can help. Thanks so much.
--
Smartin
.
- Follow-Ups:
- Re: DateDiff
- From: Joanne
- Re: DateDiff
- Prev by Date: Re: Remove first number...
- Next by Date: RE: Getting Around Nesting
- Previous by thread: RE: DatePart qn
- Next by thread: Re: DateDiff
- Index(es):
Relevant Pages
|