Solved

MS SQL Server 2008 - Cleanup Stored Procedure

Posted on 2012-12-20
5
176 Views
Last Modified: 2013-01-03
Hi,

I have attached a Stored Procedure (CleanupSP).  This Stored Procedure takes 3.22 Hours to run.  I would like to clean it up so it will run faster?.  I did not create this, but someone told me that it deals with a vertical Table??? and that is why it is like it is???

Please Help and thanks
CleanupSP.docx
0
Comment
Question by:Amour22015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 79

Expert Comment

by:arnold
ID: 38712214
How frequently does this sp have to be run?
The sp constructs five tables from complex data aggregation.
Presumably you can not alter the database structure using triggers to maintain an upto date.
Using views would sacrifice performance for seemingly an infrequent run of the query.
Checking the organization of the primary table does it include historic data or does it employ archiving where at the conclusion of the year? Does your db use partitioning based on the year??
If the data does not change, and if you can spare the storage, the sp coud create tables that include the @taxyear in the name removing the drop section.
0
 
LVL 43

Expert Comment

by:Eugene Z
ID: 38713285
for start: make sure to add appropriate indexes (run exec sp_helpindex for the tables in the query)
and insure DB maint task ran: reindex; update stats;checkdb
---

and review the code for CTE usage ( looks like it is a good candidate)
0
 

Author Comment

by:Amour22015
ID: 38727173
Hi and thanks

First let me say that I am new to Stored Procedures.

So I am at a loss on the comments made?


SP runs M, T, W at night

It was mentioned:
Checking the organization of the primary table does it include historic data or does it employ archiving where at the conclusion of the year? Does your db use partitioning based on the year??
If the data does not change, and if you can spare the storage, the sp coud create tables that include the @taxyear in the name removing the drop section

The primary table (Main Table)
does not use historic data it is based on Tax Year which in this case is 2012

the other parts I am not sure how to answer?


Mentioned:
for start: make sure to add appropriate indexes (run exec sp_helpindex for the tables in the query)
and insure DB maint task ran: reindex; update stats;checkdb
---

and review the code for CTE usage ( looks like it is a good candidate)

Need step-by-step on how to do this???

Thanks for any help and Happy new year...
0
 
LVL 43

Accepted Solution

by:
Eugene Z earned 500 total points
ID: 38731049
please read\check the below step-by-step tutorials:
/BTW: do you have DBA in your company who can check DB maint tasks?/

SQL SERVER – Stored Procedure Optimization Tips – Best Practices
http://blog.sqlauthority.com/2010/02/16/sql-server-stored-procedure-optimization-tips-best-practices/

--

Query and Stored Procedure Optimization
http://www.sqlusa.com/articles/query-optimization/



Common Table Expressions(CTE) in SQL SERVER 2008
http://www.codeproject.com/Articles/265371/Common-Table-Expressions-CTE-in-SQL-SERVER-2008
0
 

Author Closing Comment

by:Amour22015
ID: 38741483
thanks
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question