any help with this runs 45 min
- Get rid of the scalar user-defined function dbo.fnGetNumericOnly.
- Avoid the Lazy Spool over the heap scans by providing a suitable index.
- Consider rewriting the view or CTE as an in-line table-valued function so you can position parameterized predicates directly.
- Remove the RID lookups by providing covering indexes.
- Check you really need UNION rather than UNION ALL.
- Eliminate the implicit conversions.
Break the query up if possible. Many of the problems in this query plan exist because row count estimates are incorrect. Assuming base statistics are representative, this is purely down to the complexity of the query, and opaque nature of some of the operations.