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)
 Streamlining a Procedure
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

24 Posts

Posted - 03/04/2013 :  10:06:11  Show Profile  Reply with Quote
Hello. I have a massive procedure that's ran once a month which is now running 4+ hours. I need to fix this issue since. A year ago this procedure was running in 25 minutes. I was wondering if anyone can give me suggestions or direct me to a place where I can read about how to streamline this procedure. I think it's due to "Having" in the group by statement that's causing the delay but not certain... The procedure contains mutiple temp tables, updates, merge, and delete.

If someone is willing to take a look at the entire procedure I'll be more than happy to post it on here. I'm not posting the procedure on here sine this procedure is a beast and I didn't want to burden anyone too much. :)

Flowing Fount of Yak Knowledge

United Kingdom
2179 Posts

Posted - 03/04/2013 :  10:24:01  Show Profile  Visit jackv's Homepage  Reply with Quote
A year ago it was running in 25 minutes. Have the data amounts changed? or is maintenance not maintained on this server.
Have you checked the Execution Plan of this procedure? Are there large scans? For example , are statistics updated?
Read this post for a troubleshooting a slow query.

Jack Vamvas
Go to Top of Page

Flowing Fount of Yak Knowledge

6065 Posts

Posted - 03/04/2013 :  10:45:47  Show Profile  Reply with Quote
One good thing to include on these "beast" type procedures which have many different statements is to capture some basic stats for every statement. That can be as simple as adding a "print getdate()" before each statement. If the procedure is called from another process then be sure to capture the output somewhere. for example if it is called by a job you can specify an output file. That way you can see which step(s) are taking the most time so you know where to focus your energy to correct the problem.

Be One with the Optimizer

Edited by - TG on 03/04/2013 10:46:45
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 1.14 seconds. Powered By: Snitz Forums 2000