views:

146

answers:

2

Possible Duplicate:
Testing for inequality in T-SQL

Hi,

does there any different to use the '!=' vs '<>' vs 'Not'?

which one will have the worst performance

or it exist just because of the backward compatibility syntax?

+10  A: 
  • NOT does not always act the same
  • != or <> are identical, no deprecation mentioned. <> is ISO though
gbn
Yup; NOT is somewhat different. It's for things like "Blank NOT IN (stuff...)" or "Blank NOT NULL" and such.
Andrew Barber
@Andrew Barber: thanks, good example, I was just working on an example but yours covers it nicely
gbn
I was under the impression that it was actually `<>` that was the ANSI standard inequality operator.
ninesided
@ninesided: http://msdn.microsoft.com/en-us/library/ms188074.aspx
gbn
@gbn: exactly, note the "not ISO standard" in parentheses next to `!=` on the linked table!
ninesided
@onedaywhen: well done
ninesided
@onedaywhen, @ninesided: in my humble defence, it's early and not enough coffee. Thanks. gbn
gbn
+5  A: 

AFAIK, if you want to check for NULL, you must use IS NOT and not != or <>

alxx
yeah `when 'foo' = null` returns `null`, not `true` or `false`
be here now
+1 @alxx: you could use `!=` or `<>` with the result of a COALESCE, though.
Mark Bannister