title: sp_send_dbmail sending mail even if condition is false - SQL
body: <p>I have an IF statement part of a stored procedure as follows :</p>
  
  <pre><code>BEGIN TRY
  
  IF EXISTS (SELECT which I have confirmed returns no results, has a variable called from another table in the where clause)
      BEGIN           
              EXEC msdb.dbo.sp_send_dbmail 
                  @profile_name   = @dynamic_profile, 
                  @recipients     = @dynamic_recipient,
                  @subject        = @subjectline,
                  @body           = @mailHTML,   
                  @body_format    = 'HTML';
  
      END     
  END TRY
  </code></pre>
  
  <p>This is tied to a job that runs every 15mins.
  Why is it keep sending me blank emails when the IF statement asks to skip the mail sending if the select returns no results?</p>
  
  <p>My NOCOUNT is set to ON</p>