How to re write the script for maximum effencieny

Marek 2017-04-20 06:59:26

Aaron Bertrand 2017-04-26 16:33:42
How many rows in INVOICE_LINE_ITEMS in total? That seek of ~5 million rows seems like an incorrect choice. Tough to tell things from an estimated plan, though. Do you get the same plan for different parameters (like a single day, or an entire year)? It may be worth using OPTION (RECOMPILE) to prevent caching a plan optimized for small date ranges and using it for large date ranges (or vice versa).