Query to select patients by date last visit

For complex topics that regular users would not be interested in. For power users and database administrators.
Post Reply
User avatar
Jorgebon
Posts: 502
Joined: Mon Jun 18, 2007 2:25 pm
Location: Mayaguez, PR
Contact:

Query to select patients by date last visit

Post by Jorgebon » Wed Jun 29, 2011 3:39 am

July is coming soon and that's when we inactivate old physical records and store them away to make space in our office. We still don't have digital x-rays so we have folders to file away the patient's radiographs. After five years we make a list, remove them, and store them in boxes a closet. I came up with a query to make the list and it will select patients whose last visit was within a given date range. This could be useful for other purposes besides inactivating records:

SET @pos=0, @FromDate='2006-01-01' , @ToDate='2007-01-01';
SELECT pa.ChartNumber, pa.LName, pa.FName, MAX(ProcDate) AS 'Last Seen'
FROM patient pa, procedurelog pl
WHERE pl.PatNum = pa.PatNum
AND pa.patstatus = '0'
AND pl.procStatus IN(2,3)
GROUP BY pl.PatNum
HAVING (MAX(ProcDate) BETWEEN @FromDate
AND @ToDate)
ORDER BY pa.Lname;

Jorge Bonilla, DMD
Jorge Bonilla DMD
Open Dental user since May 2005

Post Reply