Where Clause and indexes

  • HI Guys,

    I saw someone post something about changing a where clause so that the Index on a date field is using a Seek instead of scan:

    HEre is a sample

    --USES A SEEK

    SELECT *

    FROM #Test

    WHERE

    somedate >= dateadd(yy,@year - 1900, 0)

    and somedate < dateadd(yy,(@year - 1900) + 1, 0)

    --USES A SCAN

    SELECT *

    FROM #Test

    WHERE

    YEAR(somedate) = @Year

    Could some please give me a breif explination of why the query plan changes here or an article I could ready about this?

    Thanks

    Chris

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • I recognize the code, and it was I.

    Here is a link to an article that may help: http://www.sqlservercentral.com/articles/Performance+Tuning+and+Scaling/bewareofsearchargumentsargdatatypes/2485/

    😎

  • indeed it was you 🙂

    thanks

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply