title: Equivalent function to IFERROR in SQL?
body: <p>I have column which is a substring of a large amount of text.</p>
  
  <p>I want to pull out the 4 characters that should be the year in YYYY format.</p>
  
  <p>If the text is incorrect it could have a text in it making it a string.</p>
  
  <p>I want to compare the year to the current year and I can't do that as the data types are different.</p>
  
  <p><code>TRY_PARSE</code> isn't a built in function.</p>
  
  <p>Also tried a few variations of:</p>
  
  <pre><code>SELECT SUBSTRING(Text, 46, 4) AS Year, 
  CASE WHEN CAST(SUBSTRING(Text, 46, 4) AS INT) IS NULL THEN 'Error'
  WHEN CAST(Year AS INT) IS NULL &lt; YEAR(GETDATE()) THEN 'In the past'
  ELSE 'In the future'
  END TEXT 
  FROM TABLE
  
  
  Example column:
  
      Year
      2011
      2018
      2022
      D200
  
  Example output required:
  
  Output
  
      'In the past'
      'In the past'
      'In the future'
      'Error'
  </code></pre>