string comparison: % vs LEFT/RIGHT

  • Is there any performance benefit to using one of these queries over the other? Or does SQL treat them exactly the same?

    1.

    select top 1 * from MyTable where MyColumn like '%mytextvalue'

    2.

    select top 1 * from MyTable where right(MyColumn, 11) = 'mytextvalue'

  • Both will result in a table or index scan because indexes will be basically worthless, but the second one (using the function) will be slower because the function must be evaluated as well as the comparison.

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

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