title: SQL - CASE expression inside WHERE
body: <p>I read about using the CASE expression inside the WHERE clause here:</p>
  
  <p><a href="http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/" rel="nofollow noreferrer">http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/</a></p>
  
  <p>I'm trying to use this to filter results from my select statement, based on a contract number which will be passed in by the user's application. My code currently throws an error of 'Invalid parameter' no matter what is passed in. I verified SELECT/FROM are working fine, as where as a WHERE clause without a CASE expression. Here is my code.</p>
  
  <pre><code>WHERE     (CASE WHEN @ContractNo = 0 THEN @ContractNo ELSE @ContractNo END =
  tblContracts.ContractNo)
  </code></pre>
  
  <p>The redundancy of the code is for troubleshooting purposes, I'm planning on using wildcard filtering on the CASE later. I'm focusing on getting the syntax down right now. I believe this should return all records for which the parameter matches the contract number stored in the table. Any help or advice would be greatly appreciated.</p>