I'm having a performance problem when I try to use datetime values in a query's WHERE clause. Performance is fine when I use a literal string that represents the datetime value:
SELECT * FROM BigTable WHERE
TargetDate > '2003-03-01'
But the query slows down when I reference a variable:
SELECT * FROM BigTable WHERE
TargetDate > @TestDate
Why is the second query much slower than the first?
...