I have the query below;
Select count(*) as poor
from records where deviceId='00019' and type='Poor' and timestamp between #14-Sep-2012 01:01:01# and #24-Sep-2012 01:01:01#
table is like;
id. deviceId, type, timestamp
data is like;
data is like;
1, '00019', 'Poor', '19-Sep-2012 01:01:01'
2, '00019', 'Poor', '19-Sep-2012 01:01:01'
3, '00019', 'Poor', '19-Sep-2012 01:01:01'
4, '00019', 'Poor', '19-Sep-2012 01:01:01'
i am trying to count the devices with a specific specific type.
Please help.. access always returns wrong data. it is returning 1 while 00019 has 4 entries for poor
Type and timestamp are both reserved words, so enclose them in square brackets in your query like this:
[type]and[timestamp]. I doubt those reserved words are the cause of your problem, but it’s hard to predict exactly when reserved words will cause query problems, so just rule out this possibility by using the square brackets.Beyond that, stored text values sometimes contained extra non-visible characters. Check the lengths of the stored text values to see whether any are longer than expected.
In comments you mentioned spaces (ASCII value 32) in your stored values. I had been thinking we were dealing with other non-printable/invisible characters. If you have one or more actual space characters at the beginning and/or end of a stored
deviceIdvalue, theTrim()function will discard them. So this query will give you different length numbers in the two columns:If the stored values can also include spaces within the string (not just at the beginning and/or end),
Trim()will not remove those. In that case, you could use theReplace()function to discard all the spaces. Note however a query which usesReplace()must be run from inside an Access application session — you can’t use it from Java code.If that query returns the same length numbers in both columns, then we are not dealing with actual space characters (ASCII value 32) … but some other type of character(s) which look “space-like”.