title: Return one value if true, return another value if not true
body: <p>I have the following example table:</p>
  
  <pre><code>ID    Type    Price    Code    Date
   1      1       .99    Null    6/1
   2      2      1.99    Null    5/1
   3      1       .99    1234    4/1
   4      3      1.99    Null    5/1
   5      2      3.99    Null    6/1
   6      1      1.30    1234    5/1
   7      1      1.64    5673    6/10
  </code></pre>
  
  <p>I need to select the following: Type, Price - for all types based upon the following rules:</p>
  
  <ol>
  <li>Where a code matches the request, take the most recent record.</li>
  <li>If all codes for a Type are Null, take the most recent record.</li>
  </ol>
  
  <p>So, the result set for a request with a Code of '1234' should be:</p>
  
  <pre><code>ID:
  4 (This is the most recent record for type 3)
  5 (This is the most recent record for type 2)
  6 (This is the most recent record for type 1 having a code = '1234')
  </code></pre>
  
  <p>I have created the following query:</p>
  
  <pre><code>Select distinct 
      ID, Type, Price, Code, Date 
  from 
      tblPRODUCT 
  where 
      Code = '1234' OR Date IN (Select MAX(Date) from tblPRODUCT Group By Type)
  </code></pre>
  
  <p>But this does not give me the correct results. Thoughts?</p>