2

I was working in MSSQL server 2012. I wrote a query

select * from Mytable where col1 is not null and  col1 != '' 

and

select * from Mytable where col1 is not null and  col1 <> ''

Both returns same value. I am just curious to know, what is the actual difference between <> and != operators?

Cebjyre
  • 6,552
  • 3
  • 32
  • 57
Shiva
  • 432
  • 8
  • 20
  • Thanks. I searched the question in stackoverflow and I could not get it. So I posted this question. But this question is duplicated:-) – Shiva Feb 26 '14 at 05:51
  • They're both not equal, which is to say they're equivalent to each other... Here are handy alternatives too: `WHERE NULLIF(col1,'') IS NOT NULL` or `WHERE ISNULL(col1,'') <> ''` – Hart CO Feb 26 '14 at 05:51

3 Answers3

4

My understanding is that there is no difference. The <> operator is the ANSI SQL standard inequality operator, while Microsoft included != to make it like some programming languages.

zchrykng
  • 1,066
  • 1
  • 10
  • 20
3

!= is not ANSI compliant.
That's all.
Use <>

UPD. Oh, here

Alexander
  • 3,129
  • 2
  • 19
  • 33
1

Technically there is no difference between != and <>. Both of them work the same way and there is absolutely no difference in terms of performance or result.

Ajay Kumar
  • 175
  • 7