Home All Groups Group Topic Archive Search About
Author
9 Feb 2006 10:02 PM
Allan
I have written a stored procedure that is using one temporary table.

When i run the statements sequentially in the query analyzer it takes about
2 minutes to process everything.

Once i put the statements into a stored procedure and execute the procedure,
it runs for about 40 minutes.

Any ideas on what could be causing this?

Author
9 Feb 2006 10:25 PM
Andrew J. Kelly
It would help to see the actual code.  Sounds like you are using a cursor.
But do you have SET NOCOUNT ON at the beginning of the stored procedure?

--
Andrew J. Kelly  SQL MVP


Show quoteHide quote
"Allan" <Al***@discussions.microsoft.com> wrote in message
news:AA869DD7-2F2C-4793-901B-82354E481ED8@microsoft.com...
>I have written a stored procedure that is using one temporary table.
>
> When i run the statements sequentially in the query analyzer it takes
> about
> 2 minutes to process everything.
>
> Once i put the statements into a stored procedure and execute the
> procedure,
> it runs for about 40 minutes.
>
> Any ideas on what could be causing this?
Are all your drivers up to date? click for free checkup

Author
9 Feb 2006 11:34 PM
Erland Sommarskog
Allan (Al***@discussions.microsoft.com) writes:
> I have written a stored procedure that is using one temporary table.
>
> When i run the statements sequentially in the query analyzer it takes
> about 2 minutes to process everything.
>
> Once i put the statements into a stored procedure and execute the
> procedure, it runs for about 40 minutes.
>
> Any ideas on what could be causing this?

There are plenty of options. The most common reason for this sort of
problems are:

1) When you ran it outside QA you had hard-coded values, when you ran the
   SP you used parameters, or even values from variables.

2) Your query involves an indexed view or an indexed computed column, and
   you created the stored procedure in Enterprise Manager, and did not
   change the settings for ANSI_NULLS and QUOTED_IDENTIFIER. They are
   OFF by default in EM, but must be ON for indexed viewes and indexed
   computed colunms to be in play. (These settings are saved with the
   procedure.)

You would need to include the procedure code, as well as the code you
run in QA to get more precise answers.

--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

Bookmark and Share