why query slow?

hsncfr 2014-09-11 06:43:29

Aaron Bertrand 2014-09-11 18:43:13
Quick observation: you have to scan all 3 million rows of the clustered index because you don't have a narrower index on LG_001_07_STINVTOT to satisfy the correlated subquery. How about an index on (date,stockref,onhand,actsorder) WHERE invenno < 4, and changing SUM(onhand)-SUM(ACTSORDER) to SUM(onhand-ACTSORDER), and changing the WHERE IN to match the where clause of the filtered index?