title: How do i "skip" a row if there is a failure on a sql function
body: <p>I want to create a stored procedure in sql server which will allow me to skip the row and move on to the next row when an error is encountered. For example, when i pass in an input of 'BOZ3C 51' it works, but fails with the error - 'Invalid length parameter passed to the LEFT or SUBSTRING function.' when it encounters an input of 'C Z3C'</p>
  
  <pre><code>BEGIN TRY
  select distinct LEFT(SUBSTRING(ticker,1,CHARINDEX(' ',ticker) -1),len(SUBSTRING(ticker,1,CHARINDEX(' ',ticker) -1))-3)as CLASS 
  from SECURITY
  SET @RETMSG = 'SUCCESS'
  END TRY
  BEGIN CATCH
  SET @RETMSG = 'SecClass ERRNUM: ' + CONVERT(VARCHAR, ERROR_NUMBER()) + ' SecClass     ERRMSG: ' + ERROR_MESSAGE();
  print @RETMSG
  END CATCH;
  </code></pre>
  
  <p>How can i handle such situations? Thanks for the pointers.</p>