Help! Stored Proc performance is very slow.
I've written a stored procedure on SQL Server that takes at most 2 seconds to execute in the query analyzer. However, when I call the stored procedure from my ASP webpage I'm getting delays of about 20-30 seconds. I know it has something to do with the stored procedure specifically because I've replaced the stored proc call and put the query (or something very close to the query) right on the page and it loads with no delay.
The syntax I'm using to call the stored proc is:
strVacSQL = "EXEC spMVP_cal " & intMonth & ", " & intYear & ", 'MARKET'"
Set rstVac = cnnMVP.execute(strVacSQL)
I replaced that with this, and it ran much more quickly:
strVacSQL = "SELECT a.act_date, s.first_name, s.last_name, a.task_code, a.payroll_id FROM mv_current a, staff s WHERE a.payroll_id = s.payroll_id AND task_code IN (61, 62, 63, 65, 66) AND DATEPART(m, a.act_date) = 12 AND DATEPART(yyyy, a.act_date) = 2003 AND a.location = 'MARKET' AND a.payroll_id = '10340' ORDER BY a.task_code
Set rstVac = cnnMVP.execute(strVacSQL)
I would leave it as above except that the first few steps of the stored proc add the contents of 3 structurally identical tables together, and then run a query against this new table, something I'm unable to do with SQL written on the webpage.
The output of the query is about 30 rows, so I don't think it's a data transfer delay or anything, and like I mentioned above, the stored proc executes in about 2 seconds or less from query analyzer. Anyone have an idea on how to speed it up or what might be causing the delay?
|