title: Send email via SQL Server Agent, based on the result of a T-SQL stored procedure
body: <p>I have a T-SQL stored procedure (which returns a single scalar value called <code>@HourDifference</code> as an output parameter); you can see the execution below:</p>
  
  <pre><code>DECLARE @HourDifference_output TINYINT;
  
  -- I declare a variable to capture the output parameter--
  
  EXEC dbo.sproc_XYZ_Notification
           @HourDifference = @HourDifference_output OUTPUT;
  
  SELECT @HourDifference_output AS HourDifferenceCaptured
  </code></pre>
  
  <p>I have the below requirements:</p>
  
  <ol>
  <li><p>If <code>HourDifferenceCaptured &gt; 12</code>, I will need to send a email</p></li>
  <li><p>If <code>HourDifferenceCaptured &lt;= 12</code>, no email needs to be sent; nothing needs to be done.</p></li>
  </ol>
  
  <p>I need to have two schedules, one at 7 AM, the other at 7 PM in the SQL Server Agent.</p>
  
  <p>Can someone provide the code and guide me through this process?</p>