title: How to convert varchar into datetime and skip not valid datetime in TSQL
body: <p>I have a database in SQL Server. I do not have authorization to change any table but I can create views. </p>
  
  <p>I have three <code>varchar</code> columns which store dates in the format <code>YYYYMMDD</code>. I want to create a view where the dates are converted from <code>varchar</code> to <code>datetime</code>. </p>
  
  <p>Now it can be the case that instead of a date in this columns I can have empty space, <code>NULL</code> or the character <code>-</code>.</p>
  
  <p>Let's take the <code>closedDate</code> column. If I use <code>CONVERT(datetime, closedDate, 112)</code> </p>
  
  <ol>
  <li><p>Valid dates are converted correctly,</p></li>
  <li><p>When there is empty space the date is converted to <code>1900-01-01</code>,</p></li>
  <li><p>NULL is kept,</p></li>
  <li><p>The <code>-</code> causes a conversion error:</p></li>
  </ol>
  
  <blockquote>
    <p><em>The conversion of a varchar data type to a datetime data type resulted
    in an out-of-range value.</em></p>
  </blockquote>
  
  <p>How can I tell to the function to convert dates just if it has valid date form and leave NULL or better an empty date(or space) in all the other cases? </p>