troubleshooting Question

select last patient appointment if the last appointment was within this year.

Avatar of tucktech
tucktech asked on
Microsoft SQL Server 2008
8 Comments4 Solutions529 ViewsLast Modified:
SQL Server Query

Hello Experts,  I need to write a sql query for SQL 2000 that has the following tables and conditions.

Tables            Fields
ApptTime                        ApptDate, ApptType, PatientID
Patient            Firstname, LastName, PatientID

ApptDate, ApptType, PatientID, Firstname, LastName

Selection Criteria:
ApptType = ‘PVT’, ‘DOS’ or ‘PHY’  or not Equal to these values
The records selected from ApptTime must be the last appointment scheduled and then must be for a specific year for the acct types listed.

For Example:
      ApptDate      ApptType      PatientID
      1/5/2011                        PVT            1111
      2/15/2011      PHY            1111
      2/22/2012      PVT            1111
      2/15/2011      DOS            2222
      8/9/2010                        PVT            2222
      3/15/2012      XXX            2222

If the selection was for 2011, no records for patient 1111 would appear because this patient had an appointment in 2012 with the specified appointment types.
The record 2/15/2011 DOS 2222 would be selected for patient 2222 because the appt in 2012 was not part of the appointment types specified.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 4 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 4 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros