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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL Execution Time
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

22 Posts

Posted - 02/12/2013 :  17:35:26  Show Profile  Reply with Quote
I have a sp with many steps within it... I am baffled at the duration it takes to run for the following reason:
I run the sql from beginning to end, it takes over an hour.
I run the sql to a certain Insert Statement. Then run the insert statement by it self it runs in four minutes...
Any help would be appreciated...


James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 02/12/2013 :  17:47:46  Show Profile  Reply with Quote
When you run separately, they are run in two batches. It may be that when you run them together (which is in a single batch), the query plan is different.

Examine the query plans in both cases and see if the combined plan is equivalent to the plans for the two-step execution stacked together. Also, in the single query plan, see which steps take long time. For those steps that consume long time, add a statement level recompilation hint. for example if it is an insert statement
INSERT INTO TheTable (col1, col2) values (1,2) OPTION(RECOMPILE)
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