CREATE PROCEDURE [dbo].[ctx_Personnel_WithRoomConflict_GetByTypeIdDepartmentIdAndDateRange] @PersonnelTypeId INT, @DepartmentId INT, @ExcludedCaseId INT, @CaseStartDateTime DATETIME, @CaseEndDateTime DATETIME AS SET NOCOUNT ON DECLARE @Start DATETIME DECLARE @End DATETIME SET @Start = CONVERT(DATETIME, CONVERT(varchar, @CaseStartDateTime, 100)) SET @End = CONVERT(DATETIME, CONVERT(varchar, @CaseEndDateTime, 100))Changing the where clause to use the Passed Parameters instead seem to make a HUGE difference. Not sure why they have it coded this way or why it makes such a difference.
WHERE m.meetingnumber <> @ExcludedCaseId AND ( (@CaseStartDateTime > m.begintime AND @CaseStartDateTime < m.endtime) OR (@CaseEndDateTime > m.begintime AND @CaseEndDateTime < m.endtime) OR (m.begintime > @CaseStartDateTime AND m.begintime < @CaseEndDateTime) OR (m.endtime > @CaseStartDateTime AND m.endtime < @CaseEndDateTime) OR(@CaseStartDateTime = m.begintime AND @End = m.endtime) )