In TSQL is it proper to use != or should one always use <> when doing Boolean comparisons? Is there any difference in performance between the two?
Asked
Active
Viewed 100 times
0
-
No difference - just personal preference – marc_s Jan 29 '14 at 20:13
-
5`!=` is not ISO standard, `<>` works in all rdbms. – Tim Schmelter Jan 29 '14 at 20:18
-
possible duplicate of [Should I use != or <> for not equal in TSQL?](http://stackoverflow.com/questions/723195/should-i-use-or-for-not-equal-in-tsql) – davmos Apr 10 '14 at 11:20
2 Answers
2
No difference just like @marc_s said but if do put it in into SQL server it will just convert it to <>
Just execute the following 2 statements,
SELECT *
FROM sys.databases
WHERE database_id != 1
SELECT *
FROM sys.databases
WHERE database_id <> 1
you will see in Actual execute plan both queries will look like this, and both have same execution plans
SELECT * FROM [sys].[databases] WHERE [database_id]<>@1
0
There is absolutely no difference in using != OR <> OPERATORS. In terms of performance, you will see no change. I use <> just to keep me aware of mistake.

Maverick
- 1,167
- 1
- 8
- 16