On The Ball
05-20-2009, 03:08 AM
Hello all, I hope you can help me. I've searched and searched, but can't find anything online of any real use.
I need to find records where AssessmentDate is within 72 hours of AdmissionDate. These columns are in different tables. AdmissionDate is in tbl_ims_pre and AssessmentDate is in dbo_UserAssessriskass. The format is 18/07/2005 17:00:00. There are other parameters but they are separate from the dates.
I'm sure this is really easy, but I just don't know how to specify the time difference.
Thanks everyone!
neileg
05-20-2009, 04:29 AM
Join the two tables in a query. Add a calculated field that uses DateDiff() to calculate the difference between the two fields in hours. Add a criterion to the calculated value of <72.
HiTechCoach
05-20-2009, 04:40 AM
Another option , is to use DateAdd()
On The Ball
05-20-2009, 05:53 AM
Thanks guys - it's easy when you ask the experts!
What I don't get is that when I do as you suggest, ie.
Expr1: DateDiff("h",[AssessmentDate],[Admission Date])
it asks me to enter dates. I get why, but I don't know how to make it reference the columns in the different tables.
neileg
05-22-2009, 12:43 AM
Can you post the SQL of your query.
On The Ball
05-22-2009, 06:00 AM
SELECT tbl_ims_pre.ClientID, tbl_ims_pre.AdmissionDate, dbo_UserAssessriskass.AssessmentDate
FROM tbl_ims_pre INNER JOIN dbo_UserAssessriskass ON tbl_ims_pre.ClientID = dbo_UserAssessriskass.ClientID
GROUP BY tbl_ims_pre.ClientID, tbl_ims_pre.AdmissionDate, dbo_UserAssessriskass.AssessmentDate
HAVING (((DateDiff("h",[AssessmentDate],[Admission Date]))<72));
That's direct from Access. I'm just not sure how to get it to look specifically at the columns in Access (they're from different tables). Apologies if there isn't sufficient info there - and thanks!
neileg
05-26-2009, 12:30 AM
HAVING (((DateDiff("h",[AssessmentDate],[Admission Date]))<72));You have a space in [Admission Date] which will generate a prompt. If the same field names occur in each table, you will need to specify the full table reference, i.e.:
HAVING (((DateDiff("h",[dbo_UserAssessriskass].[AssessmentDate],[tbl_ims_pre].[AdmissionDate]))<72));