question

PeteK avatar image
PeteK asked

Finding Unmatched Items Between Two Temp Tables

I want to return unmatched items between two temp tables. I only want to return those patients with an appointment within a stated month that have NOT been seen within the last two years: SELECT A.Sta3N ,S.PatientSSN ,D.PrimaryStopCode ,D.SecondaryStopCode ,D.LocationName ,A.AppointmentDateTime ,A.AppointmentMadeDateTime ,ST.ProviderClass ,ST.PositionTitle INTO #2yr FROM Appt.Appointment A JOIN dim.Location D ON A.LocationSID = D.LocationSID JOIN SPatient.SPatient S ON A.PatientSID = S.PatientSID JOIN SStaff.SStaff ST ON A.CheckOutStaffSID = ST.StaffSID WHERE A.STA3N = 678 AND (A.AppointmentDateTime > '2011-12-01' AND A.Appointmentdatetime < '2013-11-30 23:59:59') --@Start_date AND @End_date AND D.PrimaryStopCode IN ('322','323','350') AND A.CancelNoShowCode IS NULL AND (ST.ProviderClass LIKE '%NURSE PRACTITIONER%' OR ST.ProviderClass LIKE '%PHYSICIAN%' OR ST.ProviderClass LIKE 'CLINCIAL NURSE SPECIALIST' OR ST.ProviderClass LIKE '%RESIDENT%') ORDER BY A.APPOINTMENTDATETIME ASC SELECT A.Sta3n ,S.PatientSSN ,D.PrimaryStopCode ,D.SecondaryStopCode ,D.LocationName ,A.AppointmentDateTime ,A.AppointmentMadeDateTime ,ST.ProviderClass ,ST.PositionTitle INTO #CurrentMonth FROM Appt.Appointment A JOIN dim.Location D ON A.LocationSID = D.LocationSID JOIN SPatient.SPatient S ON A.PatientSID = S.PatientSID JOIN SStaff.SStaff ST ON A.CheckOutStaffSID = ST.StaffSID WHERE A.STA3N = 678 AND (A.AppointmentDateTime > '2013-12-01' AND A.Appointmentdatetime < '2013-12-31 23:59:59') --@Start_date AND @End_date AND D.PrimaryStopCode IN ('322','323','350') AND A.CancelNoShowCode IS NULL AND (ST.ProviderClass LIKE '%NURSE PRACTITIONER%' OR ST.ProviderClass LIKE '%PHYSICIAN%' OR ST.ProviderClass LIKE 'CLINCIAL NURSE SPECIALIST' OR ST.ProviderClass LIKE '%RESIDENT%') ORDER BY A.APPOINTMENTDATETIME ASC Any and all assistance would be appreciated!!
joinsunion
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered
What about using the EXCEPT operator? That will show you all the values on the left that don't appear on the right of the operator. That should do pretty much what you need. Read about it [in the documentation][1]. [1]: http://technet.microsoft.com/en-us/library/ms188055.aspx
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.