Hi,
When I pass a date time parameter the stored procedure takes about 45
seconds, when I hard code the parameter it returns in 1 second. How can
I rewrite my stored procedure?
@createddatelower datetime
WHERE dbo.tblCaseHistory.eventdate > dateadd(d,-7,@createddatelower )
AND dbo.tblCaseHistory.eventdate < dateadd(d,-6,@createddatelower ) (45
seconds)
vs.
WHERE dbo.tblCaseHistory.eventdate > dateadd(d,-7,'11/15/05') AND
dbo.tblCaseHistory.eventdate < dateadd(d,-6,'11/15/05') (1 second)
thanks for your help,
Paul 5 2848
Do you get the same (correct) result with both queries?
Yes, the result is the same
I've read that perhaps the sp is not using the index. The table i'm
searching is a joined table in the sp...Do you know how i can force it
to use the index? Then name of the index is IndexDate
thanks,
Paul
>Do you know how i can force it to use the index?
Check out "forceplan" as in:
set forceplan on
Paul,
Your stored procedure could benefit from parameter sniffing if you
change the local variable into a parameter, as in:
CREATE PROCEDURE MyProcedure (@createddatelower datetime) AS
...
WHERE eventdate > dateadd(day,-7,@createddatelower)
...
EXEC MyProcedure '20051115'
HTH,
Gert-Jan
paulmac106 wrote: Hi,
When I pass a date time parameter the stored procedure takes about 45 seconds, when I hard code the parameter it returns in 1 second. How can I rewrite my stored procedure?
@createddatelower datetime
WHERE dbo.tblCaseHistory.eventdate > dateadd(d,-7,@createddatelower ) AND dbo.tblCaseHistory.eventdate < dateadd(d,-6,@createddatelower ) (45 seconds)
vs.
WHERE dbo.tblCaseHistory.eventdate > dateadd(d,-7,'11/15/05') AND dbo.tblCaseHistory.eventdate < dateadd(d,-6,'11/15/05') (1 second)
thanks for your help, Paul This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: crisp99 |
last post by:
Hi,
I have a SQL Stored Procedure :
CREATE PROCEDURE spFilterOne
@city varchar(25)
AS
SELECT * FROM tblCities
WHERE tblCities.strCity = @city
ORDER BY tblCities.strName
|
by: VMI |
last post by:
Can I call a stored proc from .net with a parm that changes during the SP?
For example, I call the SP with parameter sMyVariable (which changes in the
SP), and when I access it after the SP is...
|
by: Mona |
last post by:
I have a stored procedure with a decimal parameter .
how can send the decimal value?
I try this but it gives an error , invalid cast specified.
Dim p1 As SqlParameter =...
|
by: Craig Buchanan |
last post by:
Has any one been able to get MS DataAccess Block code to populate a return
parameter in the ExecuteReader method?
If so, how?
Thanks,
Craig Buchanan
|
by: rockdale |
last post by:
Hi, All
How to get the output parameter's value when you use the SQLHelper
(Microsoft Data Access Block)?
When I try to access my ourput parm I got the following error.
...
|
by: Alan T |
last post by:
I have a string passed from another function, eg
list_employee 4
This will call the stored procedure list_employee to get details of employee
of id 4.
Is there a way to just use this...
|
by: =?Utf-8?B?QmlzaG95?= |
last post by:
Hi all,
I have an asp.net 2.0 web site with a DetailsView control to select and
insert data from database.
I made the insert statement for that DetailsView by a stored procedure.
I made some...
|
by: simonakiki |
last post by:
hi
how can if call a strored prosedure from sql server with parameters
my procedure is
ALTER PROCEDURE . ( @p_version nvarchar(100),
|
by: DhruviTrivedi |
last post by:
Is there any way to get parameter value from variable
like
@Param1 varchar(50)
@Param2 varchar(50)
set Param1 ='value1'
while --condition--
begin
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |