views:

38

answers:

1

I have a stored proc on sql server 2008 that excepts a int parameter. It does call other stored procs and have nested quires.

the problem i am facing is when i run the procedure from SQL server management studio it does not execute and times out.

If i run the queries in side the stored proc separately in another SQL server management studio it just executes all fine.

I am not able to debug the issue. will appreciate any help/pointers to dig this deep.

( i am useing the same credential when executing the proc or the query )

Thanks in advance.

+2  A: 

Could be a case of parameter sniffing.

Try assigning the sproc parameters to local variables and using those in the queries within the sproc instead.

e.g.

CREATE PROCEDURE [TestSproc]
    @Param1 INTEGER
AS
BEGIN
DECLARE @Param1_LOCAL INTEGER
SET @Param1_LOCAL = @Param1

SELECT Something
FROM Somewhere
WHERE SomeField = @Param1_LOCAL 
END
AdaTheDev
works like a charm.I scanned through the link - it explains when we have wide range of parameters we may need to disable paramter sniffing. In my case this SP was always running with one paramter range ( 1 to 8). The trick of assigning local variable seems to work but do not understand why ?
dotnetcoder
It disables parameter sniffing resulting in SQL Server finding a "general purpose" (for want of a better phrase) execution plan based on statistics.
AdaTheDev