<p>I've just come across this in a WHERE clause:</p>

<pre><code>AND NOT (t.id = @id)
</code></pre>

<p>How does this compare with:</p>

<pre><code>AND t.id != @id
</code></pre>

<p>Or with:</p>

<pre><code>AND t.id &lt;&gt; @id
</code></pre>

<p>I'd always write the latter myself, but clearly someone else thinks differently. Is one going to perform any better than the other? I know that using <code>&lt;&gt;</code> or <code>!=</code> is going to bust any hopes for using an index that I might have had, but <em>surely</em> the first approach above will suffer the same problem?</p>

[{'answer_id': 7887, 'author': 'Tim Sullivan', 'author_id': 722, 'author_profile': 'https://Stackoverflow.com/users/722', 'pm_score': 3, 'selected': False, 'text': '<p>There will be no performance hit, both statements are perfectly equal.</p>\n\n<p>HTH</p>\n'}, {'answer_id': 7890, 'author': 'DannySmurf', 'author_id': 1028, 'author_profile': 'https://Stackoverflow.com/users/1028', 'pm_score': 5, 'selected': False, 'text': '<p>Note that the != operator is not standard SQL. If you want your code to be portable (that is, if you care), use &lt;> instead.</p>\n'}, {'answer_id': 7892, 'author': 'SQLMenace', 'author_id': 740, 'author_profile': 'https://Stackoverflow.com/users/740', 'pm_score': 6, 'selected': True, 'text': "<p>These 3 will get the same exact execution plan</p>\n\n<pre><code>declare @id varchar(40)\nselect @id = '172-32-1176'\n\nselect * from authors\nwhere au_id &lt;&gt; @id\n\nselect * from authors\nwhere au_id != @id\n\nselect * from authors\nwhere not (au_id = @id)\n</code></pre>\n\n<p>It will also depend on the selectivity of the index itself of course. I always use au_id &lt;> @id myself</p>\n"}, {'answer_id': 2875218, 'author': 'LAGARRIGUE Mattiheu', 'author_id': 346274, 'author_profile': 'https://Stackoverflow.com/users/346274', 'pm_score': 4, 'selected': False, 'text': "<h4>Logic Hazard On Equality to Null To Be Considered</h4>\n<p>The equality operator generates an unknown value when there is a null\nand the unknown value is treated a <code>false</code>.\n<code>Not (unknown)</code> is still <code>unknown</code>.</p>\n<p>In the example below I'll ask if a couple <code>(a1, b1)</code> is equal to <code>(a2, b2)</code>.\nNote that each column has 3 values: <code>0</code>, <code>1</code> and <code>NULL</code>.</p>\n<pre><code>DECLARE @t table (a1 bit, a2 bit, b1 bit, b2 bit)\n\nInsert into @t (a1 , a2, b1, b2) \nvalues( 0 , 0 , 0 , NULL )\n\nselect \na1,a2,b1,b2,\ncase when (\n    (a1=a2 or (a1 is null and a2 is null))\nand (b1=b2 or (b1 is null and b2 is null))\n)\nthen \n'Equal'\nend,\ncase when not (\n    (a1=a2 or (a1 is null and a2 is null))\nand (b1=b2 or (b1 is null and b2 is null))\n)\nthen \n'Not Equal'\nend,\ncase when (\n    (a1&lt;&gt;a2 or (a1 is null and a2 is not null) or (a1 is not null and a2 is null))\nor (b1&lt;&gt;b2 or (b1 is null and b2 is not null) or (b1 is not null and b2 is null))\n)\nthen \n'Different'\nend\nfrom @t\n</code></pre>\n<p>Note that here, the results we expect are:</p>\n<ul>\n<li>Equal to be null</li>\n<li>Not equal to be not\nequal</li>\n<li>Different to be different</li>\n</ul>\n<p>But instead, we get another result</p>\n<ul>\n<li>Equal is null - what we expected.</li>\n<li><strong>Not Equal is null  ???</strong></li>\n<li>Different is different - what we expected.</li>\n</ul>\n"}]
['https://Stackoverflow.com/questions/7884', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1030/']