sql - Is there a difference between NOT (ColumnName LIKE '%a%') and ColumnName NOT LIKE '%a%' -
i came across when amending else's view in sql server.
are there differences between:
not (columnname '%a%')
and
columnname not '%a%'
are there performance differences or difference in results? or strange way (strange me anyway) sql server alters code when use query builder or view builder?
no, there's no difference.
the 2 syntaxes both make sense - not like
clearer one, it's not can disable not
(a simple unary boolean operator) in cases this.
most of time, form of query doesn't matter performance - time does, you're looking @ subtle bug in execution planner. before query gets anywhere close executing, it's torn apart, analyzed , rebuilt actual steps needed results - whenever wonder what's really happening in query, execute include actual execution plan, , you'll see.
if you're human, there's little reason not use not like
- you'd use other way part of automatic generation of code (negating result of expression), not in human written code. unless you're building query slapping strings together, of course - might make sense when write yourself.
oh, , style, note said, not
operator, not function call. proper way use parentheses either
not columnname '%a%'
or better,
(not columnname '%a%')
or, if you're crazy (or again, generating code):
(not (columnname '%a%'))
using function call syntax might confusing - , operator precedence in t-sql not intuitive (it tries hard easy use , avoid parentheses, kind of confusing sometimes). sql generators tend on cautious side, , use more parentheses strictly necessary, leads better readability (and correctness :)), while having no meaningful performance impact or anything.
Comments
Post a Comment