Thank you Peter,
On this particular case we have users creating on the ERP some invoices with an invalid project code (is like an invalid customer code).
So a simple SQL statement like this:
select * from invoices
where ProjectCode not in
(select ProjectCode from ProjectInventory)
Will tell us that incorrect invoices were created and we can fix the problem right away.
This problem happens only 1 or 2 times in a month, that is why I would like to schedule the query to be executed every day but I would like to send the email only those 1 or 2 times in the month when the “select” return rows.