Counting the number of events

T

Tom Tripicchio

I have a list of patients who had multiple visit dates. What I would to be
able to do is calculate the amount of days between each visit. That part is
easy for me to do, but I only want the number of days between the 1st visit
and the 2nd visit.

Patient visit Date
1 2/1/04
1 2/5/04
1 2/7/04
1 2/9/04

I can get the amount of time between each of these visits, but I only want
to graph the time between 2/1 and 2/5.

Thanks in advance.
 
M

MGFoster

Tom said:
I have a list of patients who had multiple visit dates. What I would to be
able to do is calculate the amount of days between each visit. That part is
easy for me to do, but I only want the number of days between the 1st visit
and the 2nd visit.

Patient visit Date
1 2/1/04
1 2/5/04
1 2/7/04
1 2/9/04

I can get the amount of time between each of these visits, but I only want
to graph the time between 2/1 and 2/5.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You can probably use the TOP 2 predicate in a subquery to get the 1st 2
dates per patient:

SELECT PatientID, VisitDate
FROM Visits As V
WHERE VisitDate In
(SELECT TOP 2 VisitDate
FROM Visits
WHERE PatientID = V.PatientID
ORDER BY VisitDate)

Then use this query as the data source for the query that calculates the
difference between the two dates.

Note: There may be ties in visit dates in the TOP 2 subquery (meaning
more than 2 dates) if the patient can have more than one visit per date.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQHwbyYechKqOuFEgEQLDoACgzpDNOioqt3vnPgPnZ8SwAvNUpYgAn1jn
R5aSYSrIQRMuU5IBIX4R9lT+
=YtGq
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top