title: "WHEN OTHERS THEN NULL" in SQL Server 2005
body: <p><code>tracking_table</code> is a log table declared as follows:</p>
  
  <pre><code>create table tracking_table (my_command nvarchar(500), my_date datetime);
  </code></pre>
  
  <p>Please suppose you have the following block of SQL SERVER 2005 code, declared within a SQL Server 2005 job:</p>
  
  <pre><code>DECLARE @my_statement NVARCHAR(500)  
  delete from tracking_table
     SET @my_statement = 'ALTER INDEX ALL ON my_user.dbo.my_fact_table REBUILD WITH (FILLFACTOR = 90)'
  insert into tracking_table values (@my_statement,getdate()) 
  EXEC (@my_statement)  
   SET @my_statement = 'ALTER INDEX ALL ON my_user.dbo.my_second_table REBUILD WITH (FILLFACTOR = 90)'
  insert into tracking_table (@my_statement,getdate())    
  EXEC (@my_statement)  
  </code></pre>
  
  <p>At runtime, if the first statement (<code>ALTER INDEX ALL ON my_user.dbo.my_fact_table REBUILD WITH (FILLFACTOR=90)</code>) fails, the second statement which acts on my_second table WON'T be executed.</p>
  
  <p>I would like to know how could I modify the SQL Server 2005 code, in order to skip any error, going forward (in Oracle I would say, <code>WHEN OTHERS THEN NULL</code>).</p>
  
  <p>How could I achieve this?</p>
  
  <p>Thank you in advance for your kind help.</p>