August 17, 2007 at 6:07 am
What is difference between != and <> operators in SQL ?
Thanks in advance
Amit Choudhary
August 17, 2007 at 6:23 am
According to Books Online, and an Execution Plan, there is no functional difference between the two expressions. However <> is the ANSI 92 compliant version, so I suppose it is preferable to use that one...
Hope that helps.
S
August 17, 2007 at 6:30 am
August 17, 2007 at 11:14 am
what's the difference between slang and formal speech? You can say the same thing using either. However, computers as a rule greatly appreciate formal speech. I believe the "!=" operator has been deprecated and will fail to work in either 2005 or 2008, whereas ANSI standards generally will work as documented.
Besides the issues of readability and style, there is also a question whether you have to care about performance.
"Don't use no double negatives!" is not exactly the same as "Always use positives" - and the shades of meaning in the difference can be the difference between forcing a table scan and using an index.
August 17, 2007 at 9:10 pm
> I believe the "!=" operator has been deprecated and will fail to work in either 2005 or 2008, whereas ANSI standards generally will work as documented.
> Besides the issues of readability and style, there is also a question whether you have to care about performance.
SQL 2005 BOL states that != functions the same as <>.
The latest CTP of SQL 2008 BOL states the same (it appears to be an unedited copy of the 2005 topic).
Niether topic, nor the corresponding topics on <>, make any reference to impending removal.
Furthermore, there is no mention that != will be removed from T-SQL anytime soon. The current command deprecation list is available in the "Deprecated Database Features in SQL Server 2005" topic (look for 'deprecated features [SQL Server] in the BOL index), either in BOL or here:
http://msdn2.microsoft.com/en-us/library/ms143729.aspx
Note there are headings in that topic for 'features not supported in the next version of SQL Server' and 'Features not supported in a future version of SQL Server'.
!=, !< and !> are all valid and will continue to be supported in T-SQL.
Outside of T-SQL, <> is the only supported not-equal-to operator for DMX and MDX, and != is the only supported not-equal-to operator in SSIS.
-Eddie
Eddie Wuerch
MCM: SQL
August 17, 2007 at 9:31 pm
!= is what most GUI folks write and it's a bit more difficult to read than <>. Other than that, no difference.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 20, 2007 at 2:47 pm
> != is most GUI folks write and it's a bit more difficult to read than <>.
Totally a matter of opinion. ! mean Not (negation operator) and = means equal so != means 'not equal'; perfectly logical and (for me) the clearest syntax. However I understand that for some people with a more VB like background the other syntax (greatest than and less than) is just as clear. I think you will find it is a matter of familiarity.
I am likely biased in this but I consider the != syntax more standard; its what I learnt as a C programmer, its used in all Unix variant (commercial or Lynix), I think its used on the mainframe. The <> syntax I have only come across in some MS products, although I note one contributer tells us it is ANSI 92 compliant.
Regards
Karl
August 20, 2007 at 4:15 pm
No... not more VB like... more mathematical like
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply