From: http://blog.csdn.net/pgbiao/article/details/22388945
Cause Analysis:
Because the stored procedure is precompiled, the execution plan is generated at the time of the first execution and is executed at a later time, using the execution plan (unless the stored procedure or the display specifies recompilation) instead of generating the execution plan each time it executes.
The stored procedure should be recompiled when the object structure involved in the stored procedure is adjusted, or the related data has changed greatly, which may result in the original plan being unsuitable for the current situation (the execution plan expires).
Workaround:
1. Manual re-compilation:
EXEC sp_recompile @objname=' stored procedure name '
2, if the execution of low-frequency stored procedures, you can set in the script to perform automatic recompilation every time, such as:
ALTER PROC [dbo]. [ stored procedure name ] @bDate DATETIME , @eDate DATETIME with -- setting up recompilation to avoid program call timeouts as BEGIN
Stored procedures are slow to execute by programs and third-party clients, and SQL Server Management Studio performs normally