473,398 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

sum query: Data type mismatch in criteria expression

Hello!
I have created a very simple query like this:

SELECT Tasks.Name, DurationHrs([Log.DateTimeFrom],[Log.DateTimeTo]) AS
Duration
FROM Tasks INNER JOIN Log ON Tasks.TaskID=Log.TaskID;

The above query works fine. "Tasks.Name" is a "Text" field with
description of task, while "DurationHrs" is a VB function that
calculates number of hours between two "DateTime" values and returns
result of type "Single".

However, when I try to sum these hours of type "Single" in a query like
this:

SELECT Tasks.Name,
Sum(DurationHrs([Log.DateTimeFrom],[Log.DateTimeTo])) AS Duration
FROM Tasks INNER JOIN Log ON Tasks.TaskID = Log.TaskID
GROUP BY Tasks.Name;

.... I get an error "Data type mismatch in criteria expression. (Error
3464)".

What could possibly be wrong?
Thanks in advance!
Kind regards,
Igor

Jan 27 '06 #1
2 9780
Igor, this problem is quite common in a JET 4 database (Access 2000 and
later).

The solution is to typecast the expression in the query. Obviously this
should be superflous if the function returns a Single, but JET 4 is much
worse at understanding the data types than previous versions were.

Try:
SELECT Tasks.Name,
CSng(Sum(DurationHrs([Log.DateTimeFrom],[Log.DateTimeTo]))) AS Duration
FROM Tasks INNER JOIN Log ON Tasks.TaskID = Log.TaskID
GROUP BY Tasks.Name;

More info:
Calculated fields misinterpreted
at:
http://allenbrowne.com/ser-45.html

Actually, JET 4 is also *much* slower executing user-defined function calls
too, so you might like to try:

CSng(Nz(Sum(DateDiff("n", [Log.DateTimeFrom], [Log.DateTimeTo]) / 60),0)) AS
Duration

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<ig***********@infotehna.si> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hello!
I have created a very simple query like this:

SELECT Tasks.Name, DurationHrs([Log.DateTimeFrom],[Log.DateTimeTo]) AS
Duration
FROM Tasks INNER JOIN Log ON Tasks.TaskID=Log.TaskID;

The above query works fine. "Tasks.Name" is a "Text" field with
description of task, while "DurationHrs" is a VB function that
calculates number of hours between two "DateTime" values and returns
result of type "Single".

However, when I try to sum these hours of type "Single" in a query like
this:

SELECT Tasks.Name,
Sum(DurationHrs([Log.DateTimeFrom],[Log.DateTimeTo])) AS Duration
FROM Tasks INNER JOIN Log ON Tasks.TaskID = Log.TaskID
GROUP BY Tasks.Name;

... I get an error "Data type mismatch in criteria expression. (Error
3464)".

What could possibly be wrong?
Thanks in advance!
Kind regards,
Igor

Jan 27 '06 #2
Allen,
Now I found your answer. No need to repeat it.
Thanks!
Igor

Jan 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: s_gregory | last post by:
The mdb is considerable size 70 +- mb. A complex union query was working well, but when an additional union select... was added into the query, selecting identical fields from a different source,...
6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
0
by: news.paradise.net.nz | last post by:
I have been developing access databases for over 5 years. I have a large database and I have struck this problem with it before but can find nothing in help or online. Access 2000 I have a query...
3
by: martlaco1 | last post by:
Trying to fix a query that (I thought) had worked once upon a time, and I keep getting a Data Type Mismatch error whenever I enter any criteria for an expression using a Mid function. Without the...
1
by: Igor Barbaric | last post by:
Hello! I have created a very simple query like this: SELECT Tasks.Name, DurationHrs(,) AS Duration FROM Tasks INNER JOIN Log ON Tasks.TaskID=Log.TaskID; The above query works fine....
10
by: aaronrm | last post by:
I have a real simple cross-tab query that I am trying to sum on as the action but I am getting the "data type mismatch criteria expression" error. About three queries up the food chain from this...
2
by: psychomad | last post by:
Please, can someone help me out to solve this error, i've been searching throughout my codes and yet i didnt succeed in finding the error!!!! The Error is: Server Error in '/' Application....
19
by: Lysander | last post by:
I have written a query that takes three integers representing day,month and year, forms a date from them and compares this date to the date the record was entered and returns any records where the...
17
by: sharsy | last post by:
Hello guys, I would like some help in generating query criteria that will identify credit cards that have expired on an access database. The specific Field is formatted with a Data Type of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.