Recently I came across an issue where I needed to set an alert that when a report is populated it needs to send out an alert. Unfortunately in SSRS you can only do subscriptions and I have not found a way to do those kinds of alerts on an SSRS report.

A workaround I found for this was to set an alert on the stored procedure the report is using. (Hoping you are using stored procedures for SSRS reports and not a large query in the report dataset) You can do this by applying the IF statement with the Execute dbmail proc. See below:

CREATE PROCEDURE dbo.DepartmentAlert
FROM HumanResources.EmployeeDepartmentHistory

--If there are more than or equal to 1 record pulled back it will fire the email.	
	FROM HumanResources.EmployeeDepartmentHistory
) >= 1
	EXEC msdb.dbo.sp_send_dbmail @profile_name = 'Alerting'
								,@recipients = ''
								,@body = 'Department history available'
								,@subject = 'Department History Availability'
								,@body_format = 'HTML'

Next I created an SSIS package that uses a SQL execute task to execute my Stored Procedure. Then scheduled this to run every few hours and when it meets the IF statement validity then the mail is sent out to alert whoever is in the @recipients list.

Hope this helps you as much as it helped me.

One thought on “Setting an Alert on a Stored Procedure

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.