Send Mail Task

  • Hi,

    i have designed a SSIS Package .that will store send query results in table and that table records will send in a email.if there is no records exist also the mail is going.

    how can we modify the ssis package if the table having no records no email to send.

    can any one suggest me..if you any questions above please post

  • Include following script in 'Execute SQL task ' of SSIS to get your output.

    IF (SELECT count(column_name) FROM tablename) <= 0

    BEGIN

    PRINT 'No email received:'

    END

    ELSE

    IF (SELECT count(column_name) FROM tablename) >0

    BEGIN

    exec msdb.dbo.sp_send_dbmail

    @profile_name = '<<Profile Name>>',-- Get this value from Server configuration

    @recipients = @Emaillist,

    @subject = 'Blah, blah',

    @body = @body

    END

    Hope this helps!

    Regards,
    Kumar

  • You could also create a variable in your package, set it to the rowcount of the table, then add a precedence constraint on your connection to the send mail task to only execute if that value of the variable > 0.

    It's basically the same thing as Arjun has suggested but involves using SSIS functionality rather than good'ole TSQL 🙂

    ______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience

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

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