I have a stored procedure which executes several queries within it, assigns results to variables and then returns the variable values as a resultset (without going into too much detail, we have a list of people in a company and their spouse/dependents, each spouse/dependent has a status and type, the SP is doing analytics on this for a particular company).
In large cases the procedure is taking 15+ seconds to execute so I commented out each query in it 1 by 1 and found that one of the queries when removed took the execution time down to 1 second. However, when I pull this query out verbatim including the variable declarations and run it by itself, it executes almost immediately with the desired result.
I can post the query if needed but I wasn't sure if this is a common symptom of another problem. TIA.