title: Convert Decode from Oracle to Case from MS SQL Server
body: <p>I have this line I am struggling with to convert a query from Oracle to SQL Server 2012. the following line is:</p>
  
  <pre><code>DECODE(SUM(DECODE(a.canceldate, NULL, 1,0)), 1, NULL, To_Date(MAX(TO_CHAR(a.canceldate,'yyyymmdd')), 'yyyymmdd')) dCancelDate,
  </code></pre>
  
  <p>As I inteprete is to convert it like:</p>
  
  <pre><code>case a.canceldate 
     (when sum(case a.canceldate when Null then 1 else 0 end)) 
     when 1 
         then 0  
         else convert(datetime,a.canceldate) 
  end max(a.canceldate) as dCancelDate,
  </code></pre>
  
  <p>I will appreciate some assistant, my line is not correct for SQL Server 2012.</p>