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

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
324255
 


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.

 
 
 

 
 
 

 
 
Group Member table excerpt
 


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

 
 
Overall (all analysts) query
 

 
 
Analyst's Group query
 


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.

 
 
 
Analyst's count of tickets query
 

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

firewall issue?  you could test with a google smart host or hotmail (if you have their accounts).  Really there isn't a whole lot to IIS smtp.

check: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/6003ab51-7eb5-47b2-8d92-e26b1deeeac1.mspx?mfr=true

Random Solutions  
 
programming4us programming4us