We help IT Professionals succeed at work.
Get Started

MS SQL 2005 Query optimization and Excel report prep - simple moving average

Last Modified: 2021-04-21
Environment:  MS SQL 2005 back end.  Choice of front ends:  Excel 2007, Crystal Report 2008, Forest & Trees, and SharePoint 2007

I am trying to create a report each month which shows a line graph comparing the count of tickets resolved by an analyst with their 12 month simple moving average (SMA) and against the SMA for their group and also the enterprise as a whole (all analysts).  A report user should be able to select a group (e.g. Tier 1) and then select a member of that group (analyst) and run the report.  I have attached a screen shot showing the results in Forest & Trees (F&T).  I don't like this interface and will create a new front end with Excel or equivilent, but that is another question...

 Screen shot of sample graph
Even though it is ugly, I can get the data.  I am using several queries cobbled from another legacy report.  Here's the process:  The first query calculates the overall SMA for the last 12 months, and then another query calculates the SMA for the group.  Finally, another query calculates the actual ticket count and SMA for the analyst.  The first 2 queries take about 30 seconds each, but the query for the analyst takes 5 minutes for each analyst.  This would take 6 days to run as is.  

My thinking is that the queries only run once a month and could be stored in new tables.  There would be separate tables for the overall and group SMAs. The analyst totals have to be calculated separately after the group is selected because an analyst can belong to more than one group.  After the tables are generated the first time, then each following month it only has to add the just completed month to the previous calculation.

For the purposes of awarding points, I will be breaking the question into several parts.  I have attached excepts of the tables invloved as well as my queries.  
Today's question:  Please review my current queries and recommend performance improvements.


The overall analyst and group average queries are getting just the raw average for every month for 24 months.  The SMA is calcuated in the front end.  In this case, F&T


The analyst query is getting just the actual count of tickets for the analyst but only where they were a member of the group assigned to the ticket.  This is the one that is taking so long.

Watch Question
This problem has been solved!
Unlock 1 Answer and 30 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE