Technical Article

Simple T-SQL implementation for running SSRS subscriptions.

,

I created this stored procedure to be able to run SSRS subscriptions using T-SQL code instead of adding a component in the SSIS package with the subscription id.

Let's say we have a set of report subscriptions named like this: ClientReport1, ClientReport2, ClientReport3. To run them using the stored procedure, all we need is this T-SQL statement:
EXECUTE [dbo].[SR_RunSubscriptions] @Pattern='ClientReport%';

 

CREATE PROCEDURE [dbo].[SR_RunSubscriptions]
         @Pattern varchar(max)
AS
BEGIN
       SET NOCOUNT ON;
       SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
       DECLARE @SubscriptionID nvarchar(max);
       DECLARE DbcurSQL CURSOR FOR
              (
             SELECT SubscriptionID FROM
             [ReportServer].dbo.[Subscriptions]
             WHERE [Description] LIKE @Pattern
              );
       OPEN DbcurSQL;
       FETCH NEXT FROM DbcurSQL INTO @SubscriptionID;
       WHILE @@FETCH_STATUS = 0
            BEGIN
                EXEC ReportServer.dbo.AddEvent @EventType='TimedSubscription',@EventData=@SubscriptionID;
                FETCH NEXT FROM DbcurSQL INTO @SubscriptionID;
            END;
       CLOSE DbcurSQL;
       DEALLOCATE DbcurSQL;
END

Rate

5 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

5 (1)

You rated this post out of 5. Change rating