Hi
I have a problem selecting records from a transaction table for a specific period. The query goes like this:
The table is very large, but 'trnDate' column is indexed.
This results in 150 records out of a total of 113000 similar records.
The problem is that it takes forever. (I gave up after a minute)
However when I tried the same thing, but hard-coding the dates, like so,
the result took only 100ms.
Is there anything that I am missing, should change or add? I hope that the problem and example are explained clearly.
Thanks
-dfs-
I have a problem selecting records from a transaction table for a specific period. The query goes like this:
Code:
DECLARE @d1 datetime
,@d2 datetime
SET @d1 = '1/Jan/2012'
SET @d2 = '11/Jan/2012'
SELECT DISTINCT BuyerName
FROM TransactionsList WITH (nolock)
WHERE trnDate BETWEEN @d1 AND @d2
The table is very large, but 'trnDate' column is indexed.
This results in 150 records out of a total of 113000 similar records.
The problem is that it takes forever. (I gave up after a minute)
However when I tried the same thing, but hard-coding the dates, like so,
Code:
DECLARE @d1 datetime
,@d2 datetime
SET @d1 = '1/Jan/2012'
SET @d2 = '11/Jan/2012'
SELECT DISTINCT BuyerName
FROM TransactionsList WITH (nolock)
WHERE trnDate BETWEEN '1/Jan/2012' AND '11/Jan/2012'
Is there anything that I am missing, should change or add? I hope that the problem and example are explained clearly.
Thanks
-dfs-