views:

768

answers:

2
+3  A: 

Any good optimizer would reduce the first expression to the second.

Otávio Décio
Well, maybe, but if it's a parameterized query where the query plan is reused, and the parameters sometimes have wildcards and sometimes not, that wouldn't be necessarily a good idea. Either way, there should be no performance penalty.
le dorfier
@le dorfier: I agree, in the generic case that is true. In the very specific and narrow case above, well, that's an easy one for the optimizer.
Otávio Décio
I'm not so sure the optimise can handle this for parm'd queries since like won't use any index
annakata
LIKE uses indexes as long as there's no wildcard at the beginning of the search string.
le dorfier
+8  A: 

As @ocdecio says, if the optimizer it's smart enough it should be no difference, but if you want to make sure about what's happening behind the scenes you should compare the two query execution plans.

CMS
Very true, the execution plan is your friend.
Otávio Décio
Man, thanks! ...gosh I'm such a noob <sigh> this is the first I've heard of 'query execution plans'
javamonkey79
We all were noobies one day.
Otávio Décio
Yeah, we always learn something new every day...
CMS