In a web application using SQL Server 2008 R2 as the backend, I have several fields, that if present, add WHERE clauses to the query.
If I was to have all queries generated as like clauses, such as:
AND Uri LIKE @Uri
Uri contains no
% , is the optimizer smart enough to treat that as
WHERE Uri = @Uri or do I have to handle that application side?
I realize that the optimizer could change out from under me someday and this is a bit sloppy, but I am still curious.
I have done a one off test that seems to suggest that this is maybe the case with the
>= ... <= conditions:
Vs. Where Clause:
So they both trigger index Seeks on that contrived Index. Is
>= ... <= the same as
= in this case, and will this always happen?