views:

296

answers:

8

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?

+3  A: 

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

Adam Robinson
+6  A: 

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
!= also works in MySQL, PostgreSQL and sqlite.
Can Berk Güder
+13  A: 

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

chburd
Woah woah woah, which is the T-SQL standard? I always thought != was the T-SQL, and <> being the MS-way?
Kezzer
T-SQL is short for Transact-SQL, which is Microsoft's SQL Server implementation of SQL. T-SQL supports ANSI SQL and more.
Adam Robinson
+1  A: 

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

Ed Harper
+2  A: 

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
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.
CodeMonkey1
Yes, that's a great point. The method you describe is more reliable.
JosephStyons
+3  A: 

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

SQL-92 standard , T-SQL

Duplicate Post..

http://stackoverflow.com/questions/723195/should-i-use-or-for-not-equal-in-tsql/723203#723203

madcolor
these should go in the comments on the question so they're easier to see
nickf
Fair point, technically an exact duplicate as the answer would be the same.
Kezzer
+1  A: 

they are identical.

Look MSDN.

pocheptsov
+1  A: 

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
Down votes with no reasoning? Gasp!
Pat