Friday, 10 February 2012

SSRS: Stored Procedures Running Slowly in SSRS

Occasionally, a stored procedure that runs quickly when executed directly can run slowly when used in a RDL dataset. One of the reasons for this can be due to the way SSRS passes query parameters to SQL Server. Unexpected parameter types can cause the cached execution plan to perform poorly.
A solution to this is to force the stored procedure to recompile the execution plan each time it is run, by adding the following query hint to the end of your procedure:
option (recompile)
It's worth pointing out that this will slightly reduce the overall speed of the procedure. So, if your procedure is called very regularly, you might want to avoid using this hint.