check if sql statement returns empty record set in ssis

Viewed 1434

I have a sql statement that when it returns nothing, I wish for the package to do nothing. If my statement returns any number of rows, I want an email to be sent. How might I accomplish this?

1 Answers

I assume that you want to send email, if rows are present for the result set.

I would suggest you to do below steps:

  1. Create an Execute SQL task and have return type as single row. Define the statement(E.g. SELECT COUNT(*) FROM Table) to return a single row. Store the result set into a variable. E.g. @cnt

  2. Define conditional expression in the precedence constraint to Send Email task. If there are rows(@cnt > 0), then email will be sent. Otherwise, email will not be sent.

You can read more on defining result set for ExecuteSQL task here here

You can read about precedence constraint expressions here

Related