tnguyen315
MIS
I'm using SQL 2008 R2, i have a query
SELECT Mpfile.PATIENT_NO AS [Patient No.], Padfile.CLINIC AS Clinic, Tbclinic.DESCRIPTION AS ClinicDesc, Padfile.APPT_DATE, Padfile.TYPE AS Type,
Padfile.DISPOSITION AS Status
FROM dbo.MPFILE AS Mpfile INNER JOIN
dbo.PADFILE AS Padfile ON Mpfile.PATIENT_NO = Padfile.PATIENT_NO INNER JOIN
dbo.TBCLINIC AS Tbclinic ON Padfile.CLINIC = Tbclinic.CLINIC
WHERE (Padfile.DISPOSITION = 'M')
GROUP BY Mpfile.PATIENT_NO, Padfile.CLINIC, Padfile.DISPOSITION, Padfile.APPT_DATE, Padfile.TYPE, Tbclinic.DESCRIPTION
ORDER BY Clinic, Padfile.APPT_DATE
If i run the time frame of Appt_Date from 12/5/2013 to 12/10/2013:
My result is:
Patient No. Clinic ClinicDesc Appt_Date Type Status
1 T1 Test1 12/5/2013 0 M
2 T1 Test1 12/10/2013 0 M
3 T2 Test2 12/8/2013 N M
However, patient 1 will have a pending appt in a next couple day
Patient No. Clinic ClinicDesc Appt_Date Type Status
1 T1 Test1 12/16/2013 0 P
How to modify the query to exclude those patients who will have pending appts (status = P) within the next 30 days.
Final result would be:
Patient No. Clinic ClinicDesc Appt_Date Type Status
2 T1 Test1 12/10/2013 0 M
3 T2 Test2 12/8/2013 N M
Please help
Thank you very much
SELECT Mpfile.PATIENT_NO AS [Patient No.], Padfile.CLINIC AS Clinic, Tbclinic.DESCRIPTION AS ClinicDesc, Padfile.APPT_DATE, Padfile.TYPE AS Type,
Padfile.DISPOSITION AS Status
FROM dbo.MPFILE AS Mpfile INNER JOIN
dbo.PADFILE AS Padfile ON Mpfile.PATIENT_NO = Padfile.PATIENT_NO INNER JOIN
dbo.TBCLINIC AS Tbclinic ON Padfile.CLINIC = Tbclinic.CLINIC
WHERE (Padfile.DISPOSITION = 'M')
GROUP BY Mpfile.PATIENT_NO, Padfile.CLINIC, Padfile.DISPOSITION, Padfile.APPT_DATE, Padfile.TYPE, Tbclinic.DESCRIPTION
ORDER BY Clinic, Padfile.APPT_DATE
If i run the time frame of Appt_Date from 12/5/2013 to 12/10/2013:
My result is:
Patient No. Clinic ClinicDesc Appt_Date Type Status
1 T1 Test1 12/5/2013 0 M
2 T1 Test1 12/10/2013 0 M
3 T2 Test2 12/8/2013 N M
However, patient 1 will have a pending appt in a next couple day
Patient No. Clinic ClinicDesc Appt_Date Type Status
1 T1 Test1 12/16/2013 0 P
How to modify the query to exclude those patients who will have pending appts (status = P) within the next 30 days.
Final result would be:
Patient No. Clinic ClinicDesc Appt_Date Type Status
2 T1 Test1 12/10/2013 0 M
3 T2 Test2 12/8/2013 N M
Please help
Thank you very much