November 20, 2019 at 5:45 pm
This is not working. It does not like the Date used, and Something about aggregate and group by clauses...
SELECT EmpNo, Date1, SUM(Time) as Expr1
FROM TimeData
WHERE (EmpNo = '8939') AND (Date1 = #11/18/2019#)
GROUP BY EmpNo
Steve Anderson
November 20, 2019 at 6:14 pm
When you use a GROUP BY
everything in the SELECT
clause has to be a property of the group. You can achieve this by using the expression to define the group (EmpNo
in this case) or by using an aggregate SUM(Time)
. Date1
is a property of individual records, not the group as a whole, because it is neither used to define the group nor is it used in an aggregate. Since you only have one possible date based on your criteria, you probably want to add it to the GROUP BY
clause.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 20, 2019 at 6:38 pm
On top of everything Drew posted, you need to change the "#' signs to single quotes and, depending on the datatype for the Time column, you might not be able to take a sum of the time.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 20, 2019 at 9:21 pm
I believe that the #
are from MS Access SQL. That's why I didn't comment on them.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 21, 2019 at 1:08 am
Ah... thanks, Drew.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 25, 2019 at 4:42 pm
Thank you.l This is what I ended up with!
SELECT EmpNo, Date1, SUM(Time) AS TotalTime
FROM TimeData
WHERE (EmpNo = @EmpNo) AND (Date1 = @Date)
GROUP BY Date1, EmpNo
Steve Anderson
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply