title: How to get error_message from SQL Server TRY.....CATCH block
body: <pre><code>BEGIN TRY
      BEGIN TRANSACTION 
        --Lots of T-SQL Code here
      COMMIT
  END TRY
  BEGIN CATCH
      ROLLBACK
      USE  [msdb];
      EXEC sp_send_dbmail 
      @profile_name='Mail Profile',
      @recipients='myEmail@mydomain.org',
      @subject='Data Error',
      @body =  SELECT ERROR_MESSAGE();
  END CATCH
  </code></pre>
  
  <p>I am getting the following error at this line</p>
  
  <pre><code>@body = SELECT ERROR_MESSAGE(); 
  </code></pre>
  
  <blockquote>
    <p>Incorrect syntax near the keyword 'SELECT'.</p>
  </blockquote>
  
  <p>Any one know why?</p>