Assume I have a T-SQL statement:
select * from MyTable
where Code != 'RandomCode'
I've been tasked with making this kind of where statement perform more quickly. Books Online says that positive queries (=) are faster than negative (!= , <>).
So, one option is make this into a CASE statement e.g.
select * from MyTable
where
case when Code = 'RandomCode' then 0
else 1 end = 1
Does anyone know if this can be expected to be faster or slower than the original T-SQL ?
Thanks in advance.
cmp-type instruction with ajmp/je/jnejump afterwards. If that 1 byte does make a huge difference to your code, then whatever you're doing is way above the level of this site.CASEoption looks overly complicated. Conditional where clauses should be avoided, because they can splinter the query plan (not in this case - no pun intended).