ReportDate TotalP12OpenOrders TotalP4OpenOrders ---------------- ----------------------------- --------------------------- 2016-06-30 1 0 2016-07-01 2 0 2016-07-02 2 1 2016-07-03 2 1 2016-07-04 2 1 2016-07-05 2 1 2016-07-06 2 1 2016-07-07 2 1 2016-07-08 2 0Interestingly enough, when using the table definitions from the script file attached to the question, I cannot see the column named OpenDate, so please change the script to accommodate it if needed. As far as the tables' design is concerned, barring the excessive number of column in one table, I believe that the following modifications will improve performance of this and many other queries against these tables: 1. Cluster the workorder table by wonum (if it is indeed a heap table now), optionally reducing the column size (no need to define it as size 50 when in reality the values are much shorter). If the wonum values are unique and most importantly, are ever-increasing, then the clustered index would be a good candidate for a clustered primary key 2. Find a suitable combination of columns to cluster the wostatus table if it is a heap table as seen from the table definition 3. Add the index on wonum to wostatus table 4. Consider indexing the OpenDate and StatusDate of the workorder table. 5. Formally relate the wostatus and workorder via foreign key on wonum column Please consider reading the excellent articles about indexes by Gail Shaw, it is 3-part series beginning from [Introduction to Indexes][1] article. Hope this helps, Oleg [1]: http://www.sqlservercentral.com/articles/Indexing/68439/
22 People are following this question.