473,407 Members | 2,314 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,407 software developers and data experts.

Criteria issue with a DateDiff

11
I currently have a query that calculates the time difference between a notifed date/time and arrival date/time along with a number of additional pieces of information incuding type of structure. I have date and time as separate fields in the main table, so first have to combine them and then subtract the combined fields to come up with a response time. Here is the code:

Expand|Select|Wrap|Line Numbers
  1. PARAMETERS [forms].[frm date selection].[start date] DateTime, [forms].[frm date selection].[end date] DateTime;
  2. SELECT tblIncidents.[Incident Number], tblIncidents.[Run Number], tblIncidents.Structure, tblIncidents.[Notified Date], tblIncidents.[Notified Time], tblIncidents.[Arrival Date], tblIncidents.[Arrival Time], [Notified Date] & " " & [Notified Time] AS Notified, [Arrival Date] & " " & [Arrival Time] AS Arrival, (DateDiff("N",[Notified],[Arrival])) AS Response
  3. FROM tblIncidents
  4. WHERE (((tblIncidents.[Run Number])=1) AND ((tblIncidents.[Notified Date]) Between ([forms].[frm date selection].[start date]) And ([forms].[frm date selection].[end date])));
From this query, I do another query that selects a particular type of structure. That works fine. Here is that code.

Expand|Select|Wrap|Line Numbers
  1. SELECT [q Response Time report - detail].[Incident Number], [q Response Time report - detail].Structure, [q Response Time report - detail].[Notified Date], [q Response Time report - detail].Response
  2. FROM [q Response Time report - detail]
  3. WHERE ((([q Response Time report - detail].Structure)="sfd"));
I then create a third query that selects some of the columns. Here is that code:

Expand|Select|Wrap|Line Numbers
  1. SELECT [q Response Time report - detail].[Incident Number], [q Response Time report - detail].Structure, [q Response Time report - detail].[Notified Date], [q Response Time report - detail].Response
  2. FROM [q Response Time report - detail]
  3. WHERE ((([q Response Time report - detail].Structure)="sfd") AND (([q Response Time report - detail].Response)>120));
My problem is when I try to put in a criteria for the response time of >120, I get the error message "Data Type mismatch in criteria expression". No matter what I do I can't seem to fix it. I've added [Response] as a parameter for Integer, but that didn't work, so I took that out. If I take out >120 as a criteria under Response I get the full list, so know my problem has something to do with the >120 but I don't know where else to look.

Thanks
Sep 6 '10 #1

✓ answered by NeoPa

I'm not sure and unable to test, but I think it may be due to data in any of your [Notified Date], [Notified Time], [Arrival Date] or [Arrival Time] fields in the table. To help ensure it's not your SQL can we make the following change to your main query so that the DateTime values are DateTime values and not strings which need to be converted automatically :
Expand|Select|Wrap|Line Numbers
  1. PARAMETERS [forms].[frm date selection].[start date] DateTime
  2.          , [forms].[frm date selection].[end date] DateTime;
  3. SELECT     [Incident Number]
  4.          , [Run Number]
  5.          , [Structure]
  6.          , [Notified Date]
  7.          , [Notified Time]
  8.          , [Arrival Date]
  9.          , [Arrival Time]
  10.          , CDate([Notified Date] & " " & [Notified Time]) AS [Notified]
  11.          , CDate([Arrival Date] & " " & [Arrival Time]) AS [Arrival]
  12.          , DateDiff("n",[Notified],[Arrival]) AS [Response]
  13. FROM       [tblIncidents]
  14. WHERE    (([Run Number]=1)
  15.   AND     ([Notified Date] Between [forms].[frm date selection].[start date]
  16.                                And [forms].[frm date selection].[end date]));

8 3838
colintis
255 100+
Does it work if you changed the "N" in the DateDiff into lowercase?

Also from one of the tries you mentioned:
I've added [Response] as a parameter for Integer
What did you tried with setting the parameter as integer?
Sep 7 '10 #2
Paul K
11
Hi Colintis

I changed to "n" but no improvment. I'm not sure about your last comment, but I added a query parameter where the parameter was "Response" and the Data Type was "Integer". This was of no help either.
Sep 7 '10 #3
NeoPa
32,556 Expert Mod 16PB
I'm not sure and unable to test, but I think it may be due to data in any of your [Notified Date], [Notified Time], [Arrival Date] or [Arrival Time] fields in the table. To help ensure it's not your SQL can we make the following change to your main query so that the DateTime values are DateTime values and not strings which need to be converted automatically :
Expand|Select|Wrap|Line Numbers
  1. PARAMETERS [forms].[frm date selection].[start date] DateTime
  2.          , [forms].[frm date selection].[end date] DateTime;
  3. SELECT     [Incident Number]
  4.          , [Run Number]
  5.          , [Structure]
  6.          , [Notified Date]
  7.          , [Notified Time]
  8.          , [Arrival Date]
  9.          , [Arrival Time]
  10.          , CDate([Notified Date] & " " & [Notified Time]) AS [Notified]
  11.          , CDate([Arrival Date] & " " & [Arrival Time]) AS [Arrival]
  12.          , DateDiff("n",[Notified],[Arrival]) AS [Response]
  13. FROM       [tblIncidents]
  14. WHERE    (([Run Number]=1)
  15.   AND     ([Notified Date] Between [forms].[frm date selection].[start date]
  16.                                And [forms].[frm date selection].[end date]));
Sep 7 '10 #4
TheSmileyCoder
2,322 Expert Mod 2GB
Have you tried modifyiung your query clause to:
Expand|Select|Wrap|Line Numbers
  1. WHERE ((([q Response Time report - detail].Structure)="sfd") AND ((clng([q Response Time report - detail].Response))>120));
Sep 7 '10 #5
Paul K
11
Hi NeoPa

Thanks for your support. I added the CDate to both of the entries but no change. In addition, I tried the addition of CLng to the criteria line as TheSmileyOne suggested but that didn't help either. I've tried both of these solutions independently and together in different combinations, but still no positive results. I don't know if it helps or make any difference, but when I get the "Data mismatch..." error box, all of the cells in the query change to #Name. Any other suggestions would be apprecited as I'm still at a loss even after playing around with it for a few more hours.

Thanks
Sep 7 '10 #6
Paul K
11
I FIGURED IT OUT!!! I went back and looked at the source data and I had one line in my main table that had an incident number and nothing else. I think it may have happened when I was earlier balancing all of the data and it got entered by error. I deleted that row and all is now fine. I knew it had to be something stupid I did!! Thanks for all of your suggestions. If nothing else, I have learned some new tricks and thinks to look at, as well as how to post properly!

Thanks again.
Sep 7 '10 #7
TheSmileyCoder
2,322 Expert Mod 2GB
Its nice to hear you got it sorted, and appreciate that you take the time to return and "close" your thread.
Sep 8 '10 #8
NeoPa
32,556 Expert Mod 16PB
Paul, remember this one!

It will come back from time-to-time and bite you on the bum if you forget it. In most cases you can code your SQL defensively to handle missing values, but it all really depends on how inappropriate the data is.

Next time you see a query that works, until you change your WHERE clause in some way, consider the data as a potential issue. As I said in post #4 the problem is almost certainly related to the data in those four fields (even though most of the data in that record is missing it would not have been a problem had all those particular fields been ok).

Well done for finding and fixing BTW :)
Sep 8 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: PMBragg | last post by:
Thank you in advance. I'm trying to pull all inventory items from December of the previous year back to 4 years for my accountant. I know this can be done, but I'm drawing a blank. I've tried; ...
1
by: PMBragg | last post by:
ORINGINAL Post >Thank you in advance. I'm trying to pull all inventory items from December >of the previous year back to 4 years for my accountant. I know this can be >done, but I'm drawing a...
3
by: T23Ij9 | last post by:
Hi. I have 3 seperate date fields. InitialDate InspDate ReportDate I am trying to setup several unbound Text boxes in a form that will give me days elapsed between these dates. These text...
5
by: mcbill20 | last post by:
Hello all. I have a really basic question that I hope someone has a better answer for. I apologize in advance-- I know this is probably a really basic question but I am used to Oracle rathern than...
3
by: acdevteam | last post by:
Hello Everyone, We are a dev team very new to Access, and so far we have gotten excellent support from this group. We have a question about writing a query. Here is the situation: We have a...
8
by: mjoytan | last post by:
In my real estate access database, I'm trying to create a report that will give me all the properties that are due for a lease renewal this year. I've been able to use datediff to tell me how...
4
by: leeg | last post by:
Please help. If I am to do what I think I need to do, i'll be here for years!!! I have 8 fields which I need to give the user the option to search on all or some or any of the combo boxes. All...
1
by: green51 | last post by:
hi I am trying to get a list of name who's birthday is 35 of days away. I have build a query with all of the information the I need. Under the field birth I enter the following criteria:...
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...
4
by: 6afraidbecause789 | last post by:
I was able to glean syntax online for a DCount on a form that counts the number of 'misbehavior' incidents for students for the current day: =DCount("StudentID","Incidents","StudentID=" & Forms!...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.