SQL Server Query
Hello Experts, I need to write a sql query for SQL 2000 that has the following tables and conditions.
ApptTime ApptDate, ApptType, PatientID
Patient Firstname, LastName, PatientID
ApptDate, ApptType, PatientID, Firstname, LastName
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.
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.