title: TSQL Query - how to get WHERE conditions to "add up"?
body: <p><strong>EDIT3:</strong></p>
  <p>I have the following table:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>item</th>
  <th>In-House Manufacturing</th>
  <th>Purchasing</th>
  <th>Outsourcing</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>A</td>
  <td>0</td>
  <td>1</td>
  <td>0</td>
  </tr>
  <tr>
  <td>B</td>
  <td>1</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>C</td>
  <td>0</td>
  <td>0</td>
  <td>1</td>
  </tr>
  <tr>
  <td>D</td>
  <td>1</td>
  <td>1</td>
  <td>0</td>
  </tr>
  <tr>
  <td>E</td>
  <td>0</td>
  <td>1</td>
  <td>1</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>The user wants to filter that data by property. Filtering for &quot;In-House Manufacturing&quot;= 1 should show items with &quot;In-House Manufacturing&quot; = 1 only. Adding a filter for &quot;purchasing&quot;= 1 to the first filter should show all items that can either be manufactured in-house or be purchased. Adding another filter for &quot;outsourcing&quot; should also show items that are outsourced.</p>
  <p>But setting any of the filters to 0 means, that I don't want to see results where that property is true.</p>
  <p>Not setting a filter for an property means: I dont' care which value that property has.</p>
  <p><strong>EDIT2:</strong>
  More clarification</p>
  <ul>
  <li><p>Var1= NULL, Var 2 = NULL, Var3 = NULL<br />
  All results are allowed</p>
  </li>
  <li><p>Var1= 1, Var 2 = NULL, Var3 = NULL<br />
  Col1 has to be 1, Col2 or col3 can be any value</p>
  </li>
  <li><p>Var1= 0, Var 2 = NULL, Var3 = NULL<br />
  Col1 has to be 0, Col2 or col3 can be any value</p>
  </li>
  <li><p>Var1= 1, Var 2 = 1, Var3 = NULL<br />
  Results with (0,0, ANY) is not allowed. (1,1,ANY) (1,0,ANY) (0,1,ANY) are allowed</p>
  </li>
  <li><p><strong>Var1= 1, Var 2 = 1, Var3 = 1<br />
  Result with (0,0,0) is not allowed. Possible Results (1/0,1/0, 1/0), (1,1,1)</strong></p>
  </li>
  <li><p>Var1= 0, Var 2 = 1, Var3 = 1<br />
  Col 1 has to be 0, Possible Results (0,1/0,1/0), Not allowed: (0,0,0)</p>
  </li>
  <li><p>Var1= 0, Var 2 = 0, Var3 = 1<br />
  Col 1 has to be 0, Col2 has to be 0, Col3 hast to be 1. Possible results (0,0,1)</p>
  </li>
  <li><p><strong>Var1= 0, Var 2 = 0, Var3 = 0<br />
  Col 1 has to be 0, Col2 has to be 0, Col3 hast to be 0. Possible results (0,0,0)</strong></p>
  </li>
  </ul>
  <p>I highlighted the difficult part. There is a difference in behaviour between the values 0 and 1. I cannot alter that logic, though. It has to work that way.</p>
  <hr />
  <p>I have 3 variables: <code>@var1, @var2, @var3</code> corresponding to 3 columns <code>@col1, @col2, @col3</code>. Each column has a value of either 1 or 0, each var can have a vlaue of 0,1 or NULL. My statement looks something like this:</p>
  <pre><code>SELECT * FROM tbl a
      ((a.col1 = @var1) OR @var1 IS NULL) AND
      ((a.col2 = @var2) OR @var2 IS NULL) AND
      ((a.col3 = @var3) OR @var3 IS NULL)
  </code></pre>