Emailing within DTS package

  • I need to create a DTS package that sends out an email based on a query.

    Query:

    SELECT @Count= count(*) FROM employee WHERE site = 1

    If @Count=0 I don't want an email to be sent. If @Count>=1 then the email should be sent out.

    How do I set up the package to reflect this?

    Thanks,

    Ninel

     

     

     

  • Add a connection object that points to your sql server.

    Add an Execute SQL Task to the package and enter the following SQL statement:

     

    DECLARE @count int

    SELECT @count = COUNT(*) FROM Employee WHERE site = 1

    IF @count > 0 

     BEGIN

      EXEC master.dbo.xp_sendmail @recipients='list of recipient email addresses, @subject='Your subject', @message='your message'

     END

  • Thank you so much. It worked.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply