|  | Posted by Erland Sommarskog on 06/14/02 11:23 
Madhivanan (madhivanan2001@gmail.com) writes:> So only in Where condition it affects the performance and not in select
 > isnt it?
 
 What matters is that if you put an indexed column into an expression,
 the index can no longer be used for searches.
 
 If you have
 
 where mydate between '20100815' and '20100917'
 
 and there is an index on mydate, SQL Server can use that index to
 find the matching rows. But if you say:
 
 convert(char(8), mydate, 112) between '20100815' and '20100916'
 
 that index can no longer be used, because that index holds datetime
 values, and this is a string expression.
 
 Note that if mydate is not indexed, the only cost for the function
 call is the function call itself. In this case, it's not more expensive
 that having it in the SELECT list. (Except that if it's in a WHERE
 clause, it may be applied to more values.)
 
 
 
 --
 Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
 
 Books Online for SQL Server SP3 at
 http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
  Navigation: [Reply to this message] |