We know that using Temp table in a stored procedure reduced the chance to reuse the execution plan. Change the temp table to temp variable
select top 1000 LimitedProgramTBNEventID into #Events from LimitedProgramTBNEvent(NOLOCK) where eventStatus = 7
we changed it as follows:
DECLARE @Events table (LimitedProgramTBNEventID int NOT NULL) insert into @Events select top 1000 LimitedProgramTBNEventID from LimitedProgramTBNEvent (NOLOCK)where eventStatus = 7
Here is another reason for not to use the Temp table. If you have a temp table then you cannot use the ‘Display Estimated execution plan"’ option in the query analyzer. When a query is run using the "Display Estimated Execution Plan" option, it does not really run so no temp tables are created. Since they are not created, any references to them in the code will fail, which prevents an estimated execution plan from being created.