Here is my query
Declare @StartDateTime datetime, @EndDateTime datetime
Select @StartDateTime = '2010-11-15', @EndDateTime = '2010-11-16'
Select PracticeCode, AccountNo, ProcCd, Modifier , ChargeDos, Paid as Amt, CreatedDate,
case When Paid > 0 then 'P'
When Paid = 0 and WrittenOff = DueAmt then 'A'
Else 'O'
End as Status
From Trn_Postings
Where CreatedDate >= @StartDateTime and CreatedDate <= @EndDateTime
--and ManualOverride in ('S','F','X','G','O')
and ManualOverride in ('N','U')
Edit : Created date is a datetime column which contains the date & time of the record created
I have individual indexes on both CreatedDate and ManualOverride. But the execution plan shows clustered index scan. The table has nearly a million record and can grow 4 to 5 times in near future.
The most surprising part is if I change the where clause like below, it uses both the indexes. I just dont know why.
Where CreatedDate >= @StartDateTime and CreatedDate <= @EndDateTime
and ManualOverride in ('S','F','X','G','O')
--and ManualOverride in ('N','U')
How do I make Sql to use the indexes...
Further if I use a Not in clause wont the index be used.