I have a stored procedure, MySProc
, that takes 7 seconds to execute.
I have made the following stored procedure, MySProcWithWhereClause
, where I simply just want to have the table from MySProc
, but with an extra WHERE
clause on it.
Here it is:
CREATE PROCEDURE MySProcWithWhereClause
BEGIN
CREATE TABLE #temptableT 'params'
INSERT INTO #temptableT
EXEC MySProc
SELECT *
FROM #temptableT
WHERE param1 = param2
DROP TABLE #temptableT
END
However, this stored procedure takes ages to execute. I waited for 2 minutes and decided I need another solution.
Why is it so slow, and is there a faster way?
I checked out other questions, for example this one, but it did not give me a proper solution.