I have a large (ish) query with 4 sub selects in the where clause:
And vw.id not In (Select Appointment_ID From AppointmentEvent Where isnull(ArrivalTime,0) <> 0 And isnull(CompleteTime,0) <> 0) And vw.id not In (Select Appointment_ID From AppointmentEvent Where Event_ID = -11 And isnull(RequestTime,0) <> 0) --Exclude Return to wait And vw.id not In (Select Appointment_ID From AppointmentEvent Where isnull(RequestTime,0) <> 0 And isnull(CompleteTime,0) = 0 And Event_ID > 0)--Exclude Any User defined Activity And vw.id not In (Select Appointment_ID From AppointmentEvent Where Event_ID = -3 And Location_ID = @Location_ID) -- Exclude patients where call has already been made
These ran OK until we got to about 14000 rows in AppointmentEvent table. Because we are looking for rows NOT IN the table is there a more efficient way to do this.
For now this combining has worked, and since this is a production environment, I'm going to run with this for now.
Thanks again saved my *rse.
Andy