Hi all
Hopefully someone can help me with this problem. I have a table in a database which shows patient contact details. From this table i have been trying to calculate a patients dependency based on the contacts made and there duration. I have written a VB program which will eventually do what i want but i am trying to speed things up by doing most of the work in queries.
My table is called [CONTACTS], the fields that are used within the table are PATIENT_NO, DATE_OF_VISIT, DURATION.
For each PATIENT_NO i need to check each of the DATE_OF_VISIT's and see how many other visits for that patient fall within a seven day period surrounding that date i.e.
if the patient has a visit date of 7/1/2004 then i need to check how many of the patients other visits fall in the periods:
1/1/2004-7/1/2004
2/1/2004-8/1/2004
3/1/2004-9/1/2004
.
.
.
7/1/2004-14/1/2004
from that i need to take the period with the most visits and use the count as a measure of dependency for the given date. e.g. if greater than 5 visits in a seven day period then dependency can be classed as high.
eventually i want to sum up the durations for the visits in each of the periods and use the maximum sum of that as well but the contact count is my main concern at present.
Hopefully this makes sense, please let me know if not.
Could anyone suggest if this is possible to do a query that can do this. If so suggest how it may be done.
Many thanks in advance
Hopefully someone can help me with this problem. I have a table in a database which shows patient contact details. From this table i have been trying to calculate a patients dependency based on the contacts made and there duration. I have written a VB program which will eventually do what i want but i am trying to speed things up by doing most of the work in queries.
My table is called [CONTACTS], the fields that are used within the table are PATIENT_NO, DATE_OF_VISIT, DURATION.
For each PATIENT_NO i need to check each of the DATE_OF_VISIT's and see how many other visits for that patient fall within a seven day period surrounding that date i.e.
if the patient has a visit date of 7/1/2004 then i need to check how many of the patients other visits fall in the periods:
1/1/2004-7/1/2004
2/1/2004-8/1/2004
3/1/2004-9/1/2004
.
.
.
7/1/2004-14/1/2004
from that i need to take the period with the most visits and use the count as a measure of dependency for the given date. e.g. if greater than 5 visits in a seven day period then dependency can be classed as high.
eventually i want to sum up the durations for the visits in each of the periods and use the maximum sum of that as well but the contact count is my main concern at present.
Hopefully this makes sense, please let me know if not.
Could anyone suggest if this is possible to do a query that can do this. If so suggest how it may be done.
Many thanks in advance