title: Multiple filters with AND and OR operator giving incorrect results
body: <p>I am trying to get list of employees based on following filters :</p>
  <pre><code>DepartmentId 
  DivisionId
  </code></pre>
  <p><strong>Use case 1:</strong> If user has selected only department as filter then ignore DivisionId and get employees only by DepartmentId</p>
  <p><strong>Use case 2:</strong> If user has selected both department and division as filter then get employees by both DepartmentId and DivisionId</p>
  <p><strong>Use case 3:</strong> If Department is not selected then get all employees(discard Department and Division filter)</p>
  <p>Query:</p>
  <pre><code>DECLARE @departmentId AS int, @divisionId AS int
  set @departmentId = 1
  set @divisionId = 100
  select * from Employees where 
  (DepartmentId is null  or 
     (DepartmentId = @departmentId and 
        (DivisionId is null or DivisionId = @divisionId)))
  </code></pre>
  <p>Problem here is I am even getting the records where DepartmentId and DivisionId both are null whereas I just want 1 record whose <code>DepartmentId = 1 and DivisionId = 100</code></p>
  <p>Can someone please help me with fixing this logical issue?</p>