title: Conversion failed when converting date and/or time from character string when selecting in CTE
body: <p>I have a question. I keep getting an error</p>
  <pre><code>CASE WHEN j.PHPPDT = '00010101' THEN '0' ELSE j.PHPPDT END AS NEWPPDT,
  
  CASE WHEN j.PHPDTE = '00010101' THEN '0' ELSE j.PHPDTE END AS NEWPROMDT
  </code></pre>
  <p>Columns <code>j.PHPPDT</code> and <code>j.PHPDTE</code> are of datatype <code>DATE</code>.</p>
  <p>When I run just them, the code seems to run. However, later with my code I create another CTE and need to select them and then  I get a mistake</p>
  <pre><code> NEWPPDT AS PrintersPortDate,
   NEWPROMDT AS PromiseByDate, 
  </code></pre>
  <p>The error is:</p>
  <blockquote>
  <p>Conversion failed when converting date and/or time from character string.</p>
  </blockquote>
  <p>I am not really sure where and how to fix it, because normally when such things happen I just use</p>
  <pre><code>WHERE CONVERT(DATE, CONVERT(CHAR(8), NEWPPDT )) 
  </code></pre>
  <p>but here it doesn't help. Further, I am not sure I understand where to even insert it. Should I insert it to <code>j.PHPPDT</code> in my case statement or when I select the column...</p>
  <p>It is pretty confusing. Does someone know what might help?</p>