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

106,024

Solution 1

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

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.

Share:
106,024
Ankush Madankar
Author by

Ankush Madankar

Working as Software Engineer having technical domain in C#, WPF, MVC, Entity Framework, ADO.NET, Linq, SQL Server. Email: [email protected]

Updated on August 07, 2022

Comments

  • Ankush Madankar
    Ankush Madankar almost 2 years

    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).