Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 why it behaves like this?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

249 Posts

Posted - 04/08/2013 :  12:24:47  Show Profile  Reply with Quote
Hi there,

I have a store procedure with 5 parameters. It runs slow. If I declare and init these 5 parameters inside the sp and highlight the scripts to run it, it runs fast, about 1 sec. But if I run it with statement as:

exec mysp p1, p2, p3 ..

it runs but takes 2 min to finish. not showing any error. What could be the reasons to cause this? Thanks in advance.

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 04/08/2013 :  12:29:50  Show Profile  Reply with Quote
Most likely the stored proc ends up using a stored execution plan that is not the most appropriate for the given set of parameters. People refer to this as "parameter-sniffing" problem - you will find references if you google for it. Examine the query plan and adding statement level recompilations at the approriate places may help.
Go to Top of Page

Posting Yak Master

249 Posts

Posted - 04/08/2013 :  17:28:08  Show Profile  Reply with Quote
Thanks James, it's very helpful. I ran the query plan and found warnings showing MISSING INDEX ... then I did research on Google got a very good source at
... then problem solved, it runs FAST now.
THANKS again.

Edited by - allan8964 on 04/08/2013 17:28:57
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 04/09/2013 :  00:02:21  Show Profile  Reply with Quote

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000