Is there any logical reason why a stored procedure would run very slow (>60 secs), but if I run the exact same code as a regular SQL script it would execute in less than 3 seconds?
To my way of thinking, they should run the same, but that is not what I am seeing. I suspect there is something else going on, but wanted to see if anyone else had seen something similar.
The situation is my client reported a slow running SP, which I confirmed, so I added an index, ran the code outside the SP and it run fantastically fast, but then I re-ran the SP and it didn’t improve.
I also dropped and re-created the SP just in case, but somehow it seems it might be using an old execution plan each time the SP runs??
could be parameter sniffing or the proc is maybe called with the setting ARITHABORT to OFF
can you show the code?