title: If date is null (SQL Server CE)
body: <p>I am trying to query a table with a <code>status</code> column and a <code>DateSent</code> column. In my query, I want to combine these two columns into one <code>sent</code> column - so that if the status is <code>c</code> (closed/sent), then display the <code>DateSent</code> - but if not, then display the appropriate status.</p>
  
  <p>Any row that is not <code>sent</code>, will have <code>DateSent</code> as NULL.</p>
  
  <p>Desired output below:</p>
  
  <pre><code>ID     Sent
  -----------------
  1      Queued
  2      Failed
  3      2013-02-28
  4      Queued
  </code></pre>
  
  <p>My current SQL Server CE query:</p>
  
  <pre><code>select 
      ID, DateAdded, 
      case when DateSent is null then 
        (case when Status='W' then 'Waiting' else 
         case when Status='O' then 'Uploaded' else 
         case when Status='F' then 'Failed' else 
         case when Status='E' then 'Expired' else 
         'Unknown' end end end end) else DateSent 
      end as Sent 
  from table
  </code></pre>
  
  <p>But the <code>else DateSent</code> part on line 7 is throwing an error:</p>
  
  <blockquote>
    <p><em>There was a syntax error in the date format. [0, 0, 0,Expression: Failed,,]</em></p>
  </blockquote>
  
  <p>Could someone help with how I might get around this problem?</p>
  
  <p>Edit: An easier-to-read snippet of the problem is:</p>
  
  <pre><code>select case when DateSent is null
  then 'null' else DateSent --&lt;---- problem is here
  end as Sent from table
  </code></pre>