Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email if have query results

Status
Not open for further replies.
Apr 18, 2002
185
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top