title: Auto-Generate Emails using SQL
body: <p>I come from a programming background, and i'm having some difficulty wrapping my head around SQL's conditionals. 
  I'm looking to auto-generate emails when two criteria are met in my sql table.</p>
  
  <p>If the value in column NextTestDate is not null AND today's date is equivalent to the next test date + 30 days  THEN generate an email. </p>
  
  <pre><code>SELECT * FROM dbo.datmaintest
  if NextTestDate is NOT NULL
  AND DATEADD(day,30,DATEDIFF(day, 0, GETDATE())) = DATEADD(DAY, DATEDIFF(day, 0, NextTest), 0) then
  
  BEGIN               
  use msdb
      GO
      EXEC sp_send_dbmail @profile_name='ControllerDB',
      @recipients='test@test.com',
      @subject='ITS ALIVE!',
      @body='Time to grab lunch'
  END
  </code></pre>