June 2, 2004 at 8:36 am
where transactiontime between '2004-04-01 05:00:00.000' and '2004-04-02 05:00:00.000'
group by sessionid
where transactiontime between @startdate and @enddate
group by sessionid
June 2, 2004 at 8:16 pm
I think you will find it is because values for the variables are not known at compile time, and therefore the execution plan is less than optimal ;-). The solution is to pass the variables in as params
create proc test( @startDate datetime, @endDate datetime) as begin
select sessionid as SessionID from transactiontable (NOLOCK)where transactiontime between @startdate and @enddate
group by sessionid
June 4, 2004 at 1:37 pm
Al makes a good point. Let's see your table defintion.
12 seconds to three minutes is a huge difference; maybe your "dynamic" code isn't using the clustered indexed as expected. Did you actually run this 3 minute version in Query Analyzer by itself and not within a stored proc? Also, check the output from the Display Estimated Execution Plan and let us know.
Eaton
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply