Queue SSRS Report Subscriptions

 T-SQL script to "queue" up SSRS report subscriptions (from my colleague Mark Horninger):

DECLARE @sql varchar(max);

 

set @sql = '';

 

select @sql = @sql + 'exec ReportServer.dbo.AddEvent @EventType=''TimedSubscription'', @EventData=''' 

 + cast(Subscriptions.SubscriptionID as varchar(500)) + ''';' + '--- '+ [catalog].name + CHAR(13) 

FROM ReportSchedule 

 INNER JOIN Schedule ON ReportSchedule.ScheduleID = Schedule.ScheduleID 

 INNER JOIN Subscriptions ON ReportSchedule.SubscriptionID = Subscriptions.SubscriptionID 

 INNER JOIN [Catalog] ON ReportSchedule.ReportID = [Catalog].ItemID 

 AND Subscriptions.Report_OID = [Catalog].ItemID

 WHERE Subscriptions.DeliveryExtension = 'Report Server Email'

 -- show only failed

 --and LEFT (subscriptions.LastStatus, 12) != 'Mail sent to'

 --and convert(varchar(20),Subscriptions.lastruntime, 101) = convert(varchar(20),getdate(), 101);

 

--EXEC(@sql);

print @sql​


Comments

Popular posts from this blog

Using sp_executesql with OPENQUERY

Executing Remote Queries Safely and Efficiently with sp_executesql