title: SQL Server: Elegant way to check if value "IS NULL" or "= integer value"
body: <p>I have a table that consists of some code-cells (for indexing purposes), and one "value" cell (where the data I am interested in lives), similar to the following:</p>
  
  <pre><code> column:      datatype:
  
    code1         int
    code2         int
    code3         int
    code4         int
    attributes    varchar(max)
  </code></pre>
  
  <p>I am checking against some input codes in the stored procedure that adds to this table, and the constraint for adding is that my INPUT codes (@code1, @code2, @code3, @code4) can either equal some value OR they may be null, but are the same as those in some matching row of the table. </p>
  
  <p>What is the best way to say the following statement:</p>
  
  <pre><code> SET @targetAttributesCell = (SELECT attributes FROM MyTable
                                 WHERE (code1 = @code1)
                                   AND (code2 = @code2)
                                   AND (code3 = @code3)
                                   AND (code4 = @code4)); &lt;-- where code1/@code1 'IS NULL' or = '[some integer]'?
  </code></pre>
  
  <p>Thanks in advance. Please let me know if I need to be more clear. </p>