ChrisDodgson
Technical User
Hi,
I have a table which shows an 'In date & time' and an 'out date & time' for people in hospital. I have to calculate how many patients were occupying a bed at midnight per day, between any two dates that the user might choose...
For example:
patientid startdate enddate
1 01/04/2003 15:30 03/04/2003 10:00
2 15/04/2003 10:50 19/04/2003 08:00
For these patients, I would want to put in a start date of 01/04/2003 and an end date of 30/04/2003 and I would expect the output to be something like the following:
date patientid
01/04/2003 1
02/04/2003 1
15/04/2003 2
16/04/2003 2
17/04/2003 2
18/04/2003 2
The way I'm currently going about it is to have a lookup table of every date over a 10 year period (in a table called bd_date - values look as follows: 01/04/2003 00:00:00.) And my code reads something like as follows:
select bd_date.[date], patients.patient_id
from bd_date, patients
where bd_date between patients.startdate and patients.enddate
however it appears to include the enddate when I don't want it to...
Any help would be greatly appreciated!
Thanks,
Chris
I have a table which shows an 'In date & time' and an 'out date & time' for people in hospital. I have to calculate how many patients were occupying a bed at midnight per day, between any two dates that the user might choose...
For example:
patientid startdate enddate
1 01/04/2003 15:30 03/04/2003 10:00
2 15/04/2003 10:50 19/04/2003 08:00
For these patients, I would want to put in a start date of 01/04/2003 and an end date of 30/04/2003 and I would expect the output to be something like the following:
date patientid
01/04/2003 1
02/04/2003 1
15/04/2003 2
16/04/2003 2
17/04/2003 2
18/04/2003 2
The way I'm currently going about it is to have a lookup table of every date over a 10 year period (in a table called bd_date - values look as follows: 01/04/2003 00:00:00.) And my code reads something like as follows:
select bd_date.[date], patients.patient_id
from bd_date, patients
where bd_date between patients.startdate and patients.enddate
however it appears to include the enddate when I don't want it to...
Any help would be greatly appreciated!
Thanks,
Chris