Home Forums SQL Server 2005 T-SQL (SS2K5) How to expand this variable for the query to work RE: How to expand this variable for the query to work

  • GSquared: Thanks for helping me out.

    I think some people are missing the point. Assuming is indexed, cast( as anything) will mean that 's index will never be used thus resulting in a table/index scan.

    It's just like converting a datetime to a string. dateTimeKey's index is useless for selectivity if it's converted like so:

    select ... from

    T where convert(char(8),T.dateTimeKey,12) = "080107"

    So searching with '%'+ cast( as varchar) + '%' is bad. It works fine for small tables because even bad SQL runs acceptably on small tables.