Hi,
I am having issues with Datetime Variables in the execution plan. I wanted to select the data for a given date from a table. When I use values in the where clause the execution plan shows as Index Seek (0% Cost). The same query if I assign the value to a variable and use it in the where clause the execution plan show as Index Scan.
For example :
Select * from tablename where dtcreated between '2009-01-01' and '2009-01-02'
The above statement shows the Index Seek.
Declare @begin datetime, @end datetime
set @begin = getdate() - 1
set @end = getdate()
select * from tablename where dtcreated between @begin and @end.
The above statement shows the Index SCAN
Can someone please let me know if you have come across these kind of issue and how to resolve it.
Thanks in advance
Sen
I am having issues with Datetime Variables in the execution plan. I wanted to select the data for a given date from a table. When I use values in the where clause the execution plan shows as Index Seek (0% Cost). The same query if I assign the value to a variable and use it in the where clause the execution plan show as Index Scan.
For example :
Select * from tablename where dtcreated between '2009-01-01' and '2009-01-02'
The above statement shows the Index Seek.
Declare @begin datetime, @end datetime
set @begin = getdate() - 1
set @end = getdate()
select * from tablename where dtcreated between @begin and @end.
The above statement shows the Index SCAN
Can someone please let me know if you have come across these kind of issue and how to resolve it.
Thanks in advance
Sen