I would like to know if the following is an error in our setup or a bug in SQL Server: if we run a certain stored procedure with three parameters, it takes about 3 minutes.
CREATE PROCEDURE [dbo].[ourProcedure]
@param1 INT,
@param2 INT,
@param3 DATETIME
AS
BEGIN...
If we run the same procedure, but in the creation we have created local copies of the parameters, it takes only 11 seconds!
CREATE PROCEDURE [dbo].[ourProcedure]
@param1_x INT,
@param2_x INT,
@param3_x DATETIME
AS
BEGIN
DECLARE @param1 INT
DECLARE @param2 INT
DECLARE @param3 DATETIME
@param1 = @param1_x
@param2 = @param2_x
@param3 = @param3_x
...
Can someone tell my WHY? Why doesn't SQL Server handle parameters like C#?
WITH RECOMPILE? Is it still the same?