Hi Naomi
The query calculates the total sales from a store many times based on the times every product were put on sales. I think the query is OK,
in the SP I change a filter and the time to run comes from more than one minute to about 12s. Athougt it is six times slower than running the statement alone, I think it is acceptable.
Very interesting the point of sniffing parameteres I´ll check
Thanks a lot