Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SProc takes MUCH longer than raw code 1

Status
Not open for further replies.
Mar 29, 2010
20
GB
Could someone please explain to me the difference in how a stored proc runs compared to just raw sql outside of a stored proc?

I created a query which creates 2 temp tables and loads them with data, then creates a 3rd temp table, inserts some rows with titles in the first column, and populates the 2nd and 3rd columns with counts and sums from the first 2 temp tables.

This query takes 1 second to run, but when put into a SProc with the date being passed as a parameter it takes 1 minute and 16 seconds.

Obviously this is a significant difference, especially given both methods use the EXACT same code.

Any ideas?
 
Do a Google search for "Parameter Sniffing." If I were a betting man, I'd wager this is your issue.
 
It certainly was, thanks very much riverguy!

I renamed the parameter, declared a variable with the old name of the parameter, set the variable to = the parameter, and hey presto!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top