I would like to set up a job that will email results from a query but if there are no results, it doesn't send the email. Any recommendations on how to do so??
DECLARE @RowCount int
SET @RowCount =0
SELECT @RowCount =count(*)
FROM MyTable
WHERE myfield = 'x'
if @RowCount > 0
BEGIN
EXEC xp_sendmail @recipients = 'xxxxxx@xxxxxx.com',
@message = 'This is a message to the user.',
@subject = 'This is the email subject.'
END
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.