I've got a Text Query that I wrote in Query Analyzer. I got it tweaked enough that it runs (though it still needs work) and takes about 2 seconds per employee. I created a stored procedure for it so that I could begin with a little testing, and I am finding the it takes the stored procedure about 40 seconds per employee.How could this be? Aren't stored procedures supposed to be faster?Here is my text in Query Analyser:Declare @Date1 DateTimeDeclare @Date2 DateTimeDeclare @Name nvarchar(100)set @Date1='08/15/2008'set @Date2='09/15/2008'set @Name='Dixie Wright'SELECT A.Serial_Number, CoilType, A.Date_Time, B.OP_ID, A.Test_Result AS 'Chamb', B.Test_Result AS 'Decay'FROM Test_Results A INNER JOIN (SELECT OP_ID, Serial_Number, System_ID, Test_Result FROM Test_Results WHERE (OP_ID=@Name) AND (System_ID Like '%Decay%') AND (Test_Result Not Like '%Abort%')) B ON (A.Serial_Number=B.Serial_Number) INNER JOIN (SELECT CoilType, Serial_Number FROM ACP_Parts WHERE (System_ID Like '%Label%')) C ON (A.Serial_Number=C.Serial_Number)WHERE (A.System_ID Like '%Chamber%') AND (A.Date_Time BETWEEN @Date1 AND @Date2)ORDER BY A.Date_Time, A.Serial_Number
Here is my stored procedure:CREATE PROCEDURE sp_BrazerAtChamb(@Name nvarchar(100), @Date1 DateTime, @Date2 DateTime) ASSELECT A.Serial_Number, CoilType, A.Date_Time, B.OP_ID, A.Test_Result AS 'Chamb', B.Test_Result AS 'Decay'FROM Test_Results A INNER JOIN (SELECT OP_ID, Serial_Number, System_ID, Test_Result FROM Test_Results WHERE (OP_ID=@Name) AND (System_ID Like '%Decay%') AND (Test_Result Not Like '%Abort%')) B ON (A.Serial_Number=B.Serial_Number) INNER JOIN (SELECT CoilType, Serial_Number FROM ACP_Parts WHERE (System_ID Like '%Label%')) C ON (A.Serial_Number=C.Serial_Number)WHERE (A.System_ID Like '%Chamber%') AND (A.Date_Time BETWEEN @Date1 AND @Date2)ORDER BY A.Date_Time, A.Serial_NumberGO
I called the stored procedure in Query Analyzer using this:exec sp_BrazerAtChamb 'Dixie Wright', '08/15/2008', '09/15/2008'
Does anyone see why my stored procedure would take longer to run than the text only version in query analyzer?Also, a minor annoyance that I have not been able to figure out yet: The stored procedure returns the same serial_number/date_time once for a Chamber Test and again for the Decay Test. I'd really like to reduce this to only seeing one for each date_time record - these serial_numbers can not physically be tested at both system_ids at the same time.
Avoid Sears Home Improvement