please advise on how to tune this query.

Angie 2017-03-03 22:13:22

Aaron Bertrand 2017-03-07 01:49:23
All of the DISTINCT CASE (and GROUP BY!), window functions, and left outer joins make it really hard to focus on what this query should really be doing. Is it possible you are trying to do data warehouse-style operations here that maybe shouldn't be in SQL Server (or at least should maybe come from aggregated / denormalized sources)? Also, because you've anonymized the plan, and it doesn't have runtime metrics (did you pull this plan from Management Studio?), it's really hard to see where the best improvements might come from. Any chance you could submit a non-anonymized, actual execution plan, generated from within Plan Explorer?