1

Duplicate of: Should I use != or <> for not equal in TSQL

Within SQL Server's T-SQL should I use "<>" or "!=", or does it really even matter?

Community
  • 1
  • 1
KM.
  • 101,727
  • 34
  • 178
  • 212
  • Duplicate - http://stackoverflow.com/questions/723195/should-i-use-or-for-not-equal-in-tsql/723203#723203 – madcolor Apr 09 '09 at 13:42

8 Answers8

15

I don't know SQLServer, but the SQL standard uses '<>', so follow the standard

chburd
  • 4,131
  • 28
  • 33
6

I believe that != is T-SQL specific (i.e. not standard SQL). So, you should use <> if there's any chance that you'll ever port your code to use a different DBMS.

Personally, I would use <> and forget about it.

Ferruccio
  • 98,941
  • 38
  • 226
  • 299
3

Typical SQL usage in my experience is to use <>. I've never seen anyone use !=; I wasn't even aware that worked.

Adam Robinson
  • 182,639
  • 35
  • 285
  • 343
3

!= isn't part of the standard, but it is part of T-SQL..

SQL-92 standard , T-SQL

Duplicate Post..

Should I use != or <> for not equal in TSQL?

Community
  • 1
  • 1
madcolor
  • 8,105
  • 11
  • 51
  • 74
2

Use <> since most people are familiar with that, and whenever NULLs are possible, remember that NULL is not equal to NULL, so this is sometimes necessary:

ISNULL(MY_FIELD,0) <> ISNULL(MY_FIELD,0)
JosephStyons
  • 57,317
  • 63
  • 160
  • 234
  • 2
    That would also equate a legit 0 to NULL, which may not be what you want. I always use (MY_FIELD1 <> MY_FIELD2 OR (MY_FIELD1 IS NULL AND MY_FIELD2 IS NULL)) but I'd be interested in seeing if someone else has a better way. – Misko Apr 09 '09 at 14:11
  • Yes, that's a great point. The method you describe is more reliable. – JosephStyons Apr 09 '09 at 14:28
1

If you only use SQL Server, it doesn't matter. They are synonyms.

Ed Harper
  • 21,127
  • 4
  • 54
  • 80
1

they are identical.

Look MSDN.

pocheptsov
  • 1,936
  • 20
  • 24
1

I'd say it comes down to your coding conventions. I personally like to use != as <> reminds me of dirty dirty VB and gives me a bad gut feeling. Plus I comprehend it better as it is exact to C#'s not equal operator.

Pat
  • 5,263
  • 1
  • 36
  • 53