Wednesday, September 3, 2014

How to Schedule/Subscribe report based on the result set in SQL Server 2012 Standard Edition?


In SQL Server 2012 Enterprise Edition, Data Driven Subscription is out of box, however if you want to subscribe report in SQL Server Standard Edition, there is a workaround to achieve this. Follow the below approach..

Step 1 : You create one new  SQL Server Jobs
            Job 1 :  Create a step with below condition

IF EXISTS (SELECT Order # FROM OrderMaster Where Ordervalue >100000)

BEGIN

                EXEC msdb.dbo.sp_start_job N' [GUID of the Subscribed Report Job]'        ;

END;

 

Job 2: This job will be automatically created when you subscribe the report, and the below step will be available in the job

exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='501e69b6-6e70-4cc8-9b60-f3fb0f1c5777'

Step 2:

Make sure the Report which is scheduled as “Run Once” , and that execution is already completed.  The whole idea is to create another Schedule job , which will trigger a already expired Subscription on demand basis, and the new Job can be scheduled based on your cycle.