• saimsaboor (5/2/2008)


    In the "where" Clause the "datename" function is Nondeterministic function also when we use "like" operator then query can not use indexes on that key resulted in table scan rather than index seek.

    I will prefer the Case Statement

    i.e.

    where

    case month(dob)

    when 1 then 1

    when 3 then 1

    when 4 then 1

    when 5 then 1

    when 7 then 1

    when 8 then 1

    else 0 end = 1

    In the above statement month is used which is deterministic function and this query will take part in index seek.

    Saim

    Hello Saim,

    Why do you think that this would result in an index seek?

    I am pretty sure that this will result in an index scan just like the "like" method.

    You need to create a persisted computed column or an indexed view to allow an index seek. Otherwise, SQL Server first has to calculate the month for all dob's which results in the mentioned scan.

    Best Regards,

    Chris Büttner