Sunday, March 11, 2012

Controling xp_sendmail

Hi,
I'd like the email be sent only when the query has results. When it doesn't
(null or 0), the email should not be sent:
EXEC master..xp_sendmail @.recipients = 'mike',
@.message = 'Message text',
@.query = '--',
@.subject = 'SQL Mail test to attach query results',
@.dbuse = 'pubs'
Howto?
TIA
MikeMike,
In this situation, you'll have to run the query twice. Once to see if you
get results, and then once in xp_sendmail.
Of course, you could pump the results from the test into a different table,
and then query that from xp_sendmail. But I'd only consider doing this if
your query really can't be run twice.
Rob
"Mike_B" wrote:

> Hi,
> I'd like the email be sent only when the query has results. When it doesn'
t
> (null or 0), the email should not be sent:
>
> EXEC master..xp_sendmail @.recipients = 'mike',
> @.message = 'Message text',
> @.query = '--',
> @.subject = 'SQL Mail test to attach query results',
> @.dbuse = 'pubs'
>
> Howto?
> TIA
> Mike
>
>

No comments:

Post a Comment