Question

I have a very large Stored Procedure that takes a single parameter @date. When I highlight the SQL code and hit execute, the query runs in about 25 seconds. But if I try to run the Stored Procedure in a separate window using:

Exec <Stored Procedure> @date = '2013-10-16'

The Stored Procedure takes about an hour and a half to run. Any ideas on why this might be happening? I am also trying to run this through BIDS and the Stored Procedure takes just as long to run.

Note: When I highlight the code to execute, I use

Declare @date as date = '2013-10-16'

to set the parameter.

Was it helpful?

Solution

When you say it runs fast if you declare the parameter variable and run the sql manually, but takes ages when you run it through BIDS I think of parameter sniffing.

Try declare a variable in your SP, then the first thing you do is assign the value of your parameter to this new local variable, then use the local variable everywhere in your SP.

For more info :http://blogs.technet.com/b/mdegre/archive/2012/03/19/what-is-parameter-sniffing.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top