What is difference between != and <> in sql server

SqlSql ServerOperators

Sql Problem Overview


What is difference between != and <> operators in Sql Server?

Since both are used as not operator. E.g :

select * from TableName where ColName <> value

or

select * from TableName where ColName != value

returns same values (Rows).

Sql Solutions


Solution 1 - Sql

There is no difference. You can use both in MSSQL.

The MSSQL doc says:

> != functions the same as the <> (Not Equal To) comparison operator.

But <> is defined in the ANSI 99 SQL standard and != is not. So not all DB engines may support it and if you want to generate portable code I recommend using <>.

Solution 2 - Sql

Most of the databases support both != and <> as not equal comparison operators. <> means either less than or greater than (i.e. not equal to) and was introduced because not all the keyboards used to have the exclamation ! key (a long time ago). Some databases like Oracle also support ^= for not equals.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnkush MadankarView Question on Stackoverflow
Solution 1 - Sqljuergen dView Answer on Stackoverflow
Solution 2 - SqlRavi K ThapliyalView Answer on Stackoverflow