title: Condition in having/where clause in sql?
body: <p>So I have a simple query that takes in the following parameters from a report (Company Code and Division Code) and returns a list of all items that are within that company and within that division of said company. </p>
  
  <p>Now I want to have the option to select all division. So instead of choosing company one division one, you could choose company one division all. </p>
  
  <p>So I added a value to my division code properties with NULL as the actual code and 'All' as the name. </p>
  
  <p>My query is long but here is the most important line</p>
  
  <pre><code>Having Style.Company_Code = @CompanyCode And Style.Division_Code = @DivisionCode
  </code></pre>
  
  <p>So at the end of the long query, it just selects all the rows with the specified company and division code. </p>
  
  <p>If I change the line to this (removing the division part completely)</p>
  
  <pre><code>Having Style.Company_Code = @CompanyCode
  </code></pre>
  
  <p>It works as intended, showing me all items from all division of a specified company, ignoring the division field completely. However, obviously, this removes the functionality of choosing a division. </p>
  
  <p>So I changed the line to this. </p>
  
  <pre><code>Having Style.Company_Code = @CompanyCode And (Style.Division_Code = @DivisionCode OR @DivisionCode = NULL)
  </code></pre>
  
  <p>If I select a division, it works as it should, but if I select 'ALL' which has a value of NULL, it just returns nothing. What am I doing wrong?  </p>