title: Conditional WHERE Clauses in SQL Server 2008
body: <p>I am trying to execute a query on a table in my SQL Server 2008 database. I have a stored procedure that uses five int parameters. Currently, my parameters are defined as follows:</p>
  
  <pre><code>@memberType int,
  @color int,
  @preference int,
  @groupNumber int,
  @departmentNumber int
  </code></pre>
  
  <p>This procedure will be passed -1 or higher for each parameter. A value of -1 means that the WHERE clause should not consider that parameter in the join/clause. If the value of the parameter is greater than -1, I need to consider the value in my WHERE clause. I would prefer to NOT use an IF-ELSE statement because it seems sloppy for this case.</p>
  
  <p>I saw this question <a href="https://stackoverflow.com/questions/2773232/sql-server-2008-conditional-query">here</a>. However, it did not work for me. I think the reason why is because each of the columns in my table can have a NULL value. Someone pointed this scenario out in the fifth answer. That appears to be happening to me. </p>
  
  <p>Is there a slick approach to my question? Or do I just need to brute force it (I hope not :().</p>
  
  <p>Thank you!</p>