Why isn't my query sorting (ordering) properly

R

red6000

Hi I ahve the following code:

SELECT Activities.TaskName, DSum("TimeSpent","Activities","TaskName = '" &
[TaskName] & "'") AS TotalTime
FROM Activities
WHERE (((Month([WorkDate]))=[Enter Month]) AND ((Activities.CSTRName)=[Enter
CSTR]))
GROUP BY Activities.TaskName, Activities.WorkDate
ORDER BY DSum("TimeSpent","Activities","TaskName = '" & [TaskName] & "'")
DESC;

However, the order is in alphabetical and not numerical, ie:

1
11
2
22
3
33

instead of

1
2
3
11
22
33

Any ideas why? The record type for 'TimeSpent' is set as 'Number' in the
table??

Thanks
 
G

Guest

Surpisingly the ORDER BY clause will interpret the return value of the DSum
function as a text expresssion, so change it to the following, using the Val
function to return a numeric value:

ORDER BY Val(DSum("TimeSpent","Activities","TaskName = '" & [TaskName] &
"'")) DESC;

If you are using this query as the RecordSource of a report, however, omit
the ORDER BY clause completely and use the report's internal sorting
mechanism.

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top