title: Dealing with errors while parsing strings
body: <p>I'm tasked with pulling relevent data out of a field which is essentially free text.  I have been able to get the information I need 98% of the time by looking for keywords and using CASE statements to break the field down into 5 different fields.</p>
  <p>My issue is I can't get around the last 2% because the errors don't follow any logical order - they are mostly misspellings.</p>
  <p>I could bypass the field with a TRY CATCH, but I don't like giving up 4 good pieces of data when the routine is choking on one.</p>
  <p>Is there any way to handle blanket errors within a CASE statement, or is there another option?</p>
  <p>Current code, the 'b' with the commented out section is where it's choking right now:</p>
  <pre><code>CASE WHEN @Location = 0 THEN 
          CASE WHEN @Duration = 0 THEN 
              CASE WHEN @Timing = 0 THEN
                      SUBSTRING(@Comment,@Begin, @Context-@Begin)
                  ELSE
                      SUBSTRING(@Comment,@Begin, @Timing-@Begin)
                  END
              ELSE SUBSTRING(@Comment,@Begin, @Duration-@Begin)
              END
          ELSE SUBSTRING(@Comment,@Begin, @Location-@Begin)
      END AS Complaint
  ,CASE WHEN @Location = 0 THEN ''
      ELSE    
          CASE WHEN @Duration = 0 THEN 
              CASE WHEN @Timing = 0 THEN SUBSTRING(@Comment,@Location+10, (@CntBegin-11))
                  ELSE SUBSTRING(@Comment,@Location+10, @Timing-(@Location+10))
              END
          ELSE SUBSTRING(@Comment,@Location+10, @Duration-(@Location+10))
          END
      END  AS Location
  ,CASE WHEN @Timing = 0 THEN ''
      ELSE
          CASE WHEN @CntBegin = 0 THEN
              SUBSTRING(@Comment,@Timing+@TimingEnd, (@Location+@Context)-(@Timing+@TimingEnd))
          ELSE
              'b'--SUBSTRING(@Comment,@Timing+@TimingEnd, (@Location+@CntBegin-1)-(@Timing+@TimingEnd))
          END
      END AS Timing
  </code></pre>
  <p>On this statement, which has a comma in an odd spot.  I have to reference the comma usually for the @CntBegin, but in this case it's making my (@Location+@CntBegin-1) shorter then the (@Timing+@TimingEnd):</p>
  <p>'Pt also presents with/for mild check MGP/MGD located in OU, since 12/2015 ? Stability.'</p>
  <p>Please take into account, I'm not necessarily trying to fix this error, I'm looking for a way to handle any error that comes up as who knows what someone is going to type.  I'd like to just display 'ERR' in that particular field when the code runs into something it can't handle.  I just don't want the routine to die.</p>