I have a query that I'm converting a datetime field to a datetimefield that will have the time be 00:00:00 so I can do a direct comparision so I can say something like this:
orderdate = '2001-07-15' otherwise I have to do
orderdate >= 2001-07-15 and < 2001-07-16
When I use the convert in my quereis it no longer uses my index but if I don't use the convert function it uses my index. Is there a way to get it to use the index while using the convert function. I'm using sql server 7.0 SP2
Here' the sql statement with the convert:
SELECT
dbo.Store.ZoneCode,
sum(dbo.SalesHeaderRetail.TotalMerchandise),
CONVERT(SMALLDATETIME,CONVERT(CHAR(10),dbo.SalesHeaderRetail.TransactionDate,101))
FROM
dbo.Store,
dbo.SalesHeaderRetail
WHERE
( dbo.SalesHeaderRetail.StoreNumber=dbo.Store.StoreNum )
AND (
CONVERT(SMALLDATETIME,CONVERT(CHAR(10),dbo.SalesHeaderRetail.TransactionDate,101)) > '07/15/2001 00:0:0'
)
GROUP BY
dbo.Store.ZoneCode,
CONVERT(SMALLDATETIME,CONVERT(CHAR(10),dbo.SalesHeaderRetail.TransactionDate,101))
Basically the query above doesn't use any indexes. If I take the convert out it uses and nonclustered index from store table and a nonclustred index from salesheaderretail. Is there anything I can do to have it use the indexes when using the convert.
orderdate = '2001-07-15' otherwise I have to do
orderdate >= 2001-07-15 and < 2001-07-16
When I use the convert in my quereis it no longer uses my index but if I don't use the convert function it uses my index. Is there a way to get it to use the index while using the convert function. I'm using sql server 7.0 SP2
Here' the sql statement with the convert:
SELECT
dbo.Store.ZoneCode,
sum(dbo.SalesHeaderRetail.TotalMerchandise),
CONVERT(SMALLDATETIME,CONVERT(CHAR(10),dbo.SalesHeaderRetail.TransactionDate,101))
FROM
dbo.Store,
dbo.SalesHeaderRetail
WHERE
( dbo.SalesHeaderRetail.StoreNumber=dbo.Store.StoreNum )
AND (
CONVERT(SMALLDATETIME,CONVERT(CHAR(10),dbo.SalesHeaderRetail.TransactionDate,101)) > '07/15/2001 00:0:0'
)
GROUP BY
dbo.Store.ZoneCode,
CONVERT(SMALLDATETIME,CONVERT(CHAR(10),dbo.SalesHeaderRetail.TransactionDate,101))
Basically the query above doesn't use any indexes. If I take the convert out it uses and nonclustered index from store table and a nonclustred index from salesheaderretail. Is there anything I can do to have it use the indexes when using the convert.