Add 'WITH RECOMPILE'. (right after the 'as' in create procedure). or run this code:
Code:
execute sp_execresultset N'select ''execute sp_recompile '' + quotename(routine_name) from information_schema.routines where routine_type = ''procedure'' and objectproperty(object_id(routine_schema + ''.'' + quotename(routine_name)), ''IsMSShipped'') = 0'
go
If that doesn't work because the statement is too large, run this one:
Code:
declare @FieldHolder sysname
declare @SQlToExecute nvarchar(4000)
declare Cursor_Proc cursor local fast_forward for
select routine_name from information_schema.routines where routine_type = 'procedure' and objectproperty(object_id(routine_schema + '.' + quotename(routine_name)), 'IsMSShipped') = 0
open Cursor_Proc
while 1 = 1 [COLOR=green]/* do until we get an error on fetch */[/COLOR]
begin
fetch next from Cursor_Proc into @FieldHolder
if @@error <> 0 or @@fetch_status <> 0 break
set @SQlToExecute = N'execute sp_recompile ' + quotename(@FieldHolder)
execute sp_executesql @SQlToExecute
end
close Cursor_Proc
deallocate Cursor_Proc
go
Dollars to donuts says the query plan is stale and recompiling it will solve the problem. Check here for the plan:
Code:
SELECT [cp].[refcounts], [cp].[usecounts], [cp].[objtype], [st].[dbid], [st].[objectid], [st].[text], [qp].[query_plan]
FROM sys.dm_exec_cached_plans cp
CROSS APPLY sys.dm_exec_sql_text ( cp.plan_handle ) st
CROSS APPLY sys.dm_exec_query_plan ( cp.plan_handle ) qp
Save the queryplan XML text from that resultset with an extension of .sqlplan and you can display a graphical plan even without the SHOWPLAN access. You need VIEW SERVER STATE access to run the query I put in above.