title: T-SQL WHERE clause - comparing column to itself fails on null columns
body: <p>I usually use a construct like this to apply filters to columns:</p>
  
  <pre><code>CREATE TABLE test(a int NOT NULL, b int NULL)
  --insert some data
  INSERT INTO test(a,b) values (1,1)
  INSERT INTO test(a,b) values (1,NULL)
  
  declare @a int
  declare @b int
  set @a = 1
  --@b is null at this time
  
  select * from test
    where a = @a
      and b = isnull(@b,b)
  </code></pre>
  
  <p>This only selects the first row.</p>
  
  <p>For example, if this was a stored procedure and argument <code>@b</code> was null, I could specify its value to 'enable' it in the <code>where</code> clause, and specify <code>NULL</code> value to select where b=b, which would be true for each column, <strong>BUT</strong> if there is a <code>NULL</code> value in <code>b</code> column, it does not get selected. Is there a standard way to deal with this? So what should I use in the above example query to select all rows even if <code>b</code> column has null values?</p>