Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Execution of Subscribed report through Stored procedure Expand / Collapse
Author
Message
Posted Monday, June 27, 2011 2:12 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, April 10, 2014 6:53 AM
Points: 82, Visits: 158
Hi,

I have a requirment where reports which are subscribed needs to executed through the Stored procedure

I mean for eg My Subscription Id
is 18EC9ADE-E538-46C0-AB78-2D1FF950CE85

so what i want to do is
EXEC 18EC9ADE-E538-46C0-AB78-2D1FF950CE85 along with passing the parameters required to generate the report

can any please help me out...
Thanking You
Post #1131922
Posted Monday, June 27, 2011 7:21 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, July 24, 2014 8:41 AM
Points: 2,818, Visits: 2,553
All SSRS subscriptions are SQL Server Agent Jobs. Use the following script to figure out which Agent job corresponds to which subscription. Run this against your reporting services database
SELECT
cat.[Name] AS RptName
, U.UserName
, cat.[Path]
, res.ScheduleID AS JobID
, sub.LastRuntime
, sub.LastStatus
, LEFT(CAST(sch.next_run_date AS CHAR(8)) , 4) + '-'
+ SUBSTRING(CAST(sch.next_run_date AS CHAR(8)) , 5 , 2) + '-'
+ RIGHT(CAST(sch.next_run_date AS CHAR(8)) , 2) + ' '
+ CASE WHEN LEN(CAST(sch.next_run_time AS VARCHAR(6))) = 5
THEN '0' + LEFT(CAST(sch.next_run_time AS VARCHAR(6)) , 1)
ELSE LEFT(CAST(sch.next_run_time AS VARCHAR(6)) , 2)
END + ':'
+ CASE WHEN LEN(CAST(sch.next_run_time AS VARCHAR(6))) = 5
THEN SUBSTRING(CAST(sch.next_run_time AS VARCHAR(6)) , 2 , 2)
ELSE SUBSTRING(CAST(sch.next_run_time AS VARCHAR(6)) , 3 , 2)
END + ':00.000' AS NextRunTime
, CASE WHEN job.[enabled] = 1 THEN 'Enabled'
ELSE 'Disabled'
END AS JobStatus
, sub.ModifiedDate
, sub.Description
, sub.EventType
, sub.Parameters
, sub.DeliveryExtension
, sub.Version
FROM
dbo.Catalog AS cat
INNER JOIN dbo.Subscriptions AS sub
ON cat.ItemID = sub.Report_OID
INNER JOIN dbo.ReportSchedule AS res
ON cat.ItemID = res.ReportID
AND sub.SubscriptionID = res.SubscriptionID
INNER JOIN msdb.dbo.sysjobs AS job
ON CAST(res.ScheduleID AS VARCHAR(36)) = job.[name]
INNER JOIN msdb.dbo.sysjobschedules AS sch
ON job.job_id = sch.job_id
INNER JOIN dbo.Users U
ON U.UserID = sub.OwnerID
ORDER BY
U.UserName
, RptName

Once you know what the appropriate agent job is, disable it. Then you can create another agent job that executes the agent job using sp_start_job. The only issue here is you will have to build your reports with default parameters.
Post #1132101
Posted Monday, June 27, 2011 10:14 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, April 10, 2014 6:53 AM
Points: 82, Visits: 158
Hi Daniel

Thanks for your reply
But in my requirment the parameters are bound to change at runtime
so is not possible to pass the parameters to the report at runtime
if i want to execute the subscribed report through stored procedure
Post #1132607
Posted Tuesday, June 28, 2011 2:50 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, July 24, 2014 8:41 AM
Points: 2,818, Visits: 2,553
Then try passing your run time parameters to a database table, and make your subscription a data driven subscription that can read that table for the current parameters
Post #1133262
Posted Wednesday, July 6, 2011 2:43 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Sunday, July 20, 2014 9:06 PM
Points: 2,693, Visits: 1,202
Firstly, I'd ask what is behind the requirement to run the subscription using T-SQL? That really defeats the purpose of setting up the subscription in the first place. When you create a subscription you're saying "run this report, with these parameter values, at this time".

Using a data-driven subscription, you're making the parameter values dynamic, but you would still have the SQL Agent job running the subscription at the specified time.

If you disable the SQL Agent job and run the subscription yourself, you're saying "I don't want to run the report at the time I specified". You'd also have to make sure that the job stays disabled in case someone inadvertantly enables it.

Personally, I'd put some effort into running the reports programatically via the web service. That removes the subscription, its stored parameters and the associated SQL Agent job.

This article has an example of rendering a report via the web service and saving the results to a file,
http://msdn.microsoft.com/en-us/library/reportexecution2005.reportexecutionservice.render(v=SQL.100).aspx

Also, @Daniel Bowlin, saying "All SSRS subscriptions are SQL Server Agent Jobs" is not entirely correct. The SQL Agent job is purely the triggering mechanism for the subscription. All the job does is put the subscription ID into the EventData table in the ReportServer database. Once that is done the job is complete. The Reporting Services service polls that table to find the subscriptions that need to run.

Use this instead of linking directly to the sysjobschedules table and you avoid returning duplicate rows when the SQL Agent job has many schedules,
SELECT
[job_id]
,MIN(CASE
WHEN next_run_time > 0
THEN DATEADD(ss, (CAST(next_run_time/10000 AS INT)* 3600
+ (CAST(next_run_time/100 AS INT)%100)*60
+ (next_run_time%100))
, CAST(CAST(next_run_date AS VARCHAR(8)) AS DATETIME))
WHEN next_run_date > 0
THEN CAST(CAST(next_run_date AS VARCHAR(8)) AS DATETIME)
ELSE '1900-01-01'
END
) AS NextRunTime
FROM msdb.dbo.sysjobschedules
GROUP BY [job_id]




Hope this helps
Phill Carter
--------------------
Colt 45 - the original point and click interface

Australian SQL Server User Groups - My profile
Phills Philosophies
Murrumbeena Cricket Club
Post #1137083
Posted Monday, June 17, 2013 3:08 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, July 24, 2014 7:43 AM
Points: 371, Visits: 954
philcart (7/6/2011)
Firstly, I'd ask what is behind the requirement to run the subscription using T-SQL? That really defeats the purpose of setting up the subscription in the first place. When you create a subscription you're saying "run this report, with these parameter values, at this time".


Lack of a version other than Standard is the most likely cause. If you have a single report that has to be run for 10-20 "groups" via a different value for a parameter you you find yourself in the position the OP is or was in. I'm facing the same thing and I don't want to write a web-based front end because we already have something like that to setup all the details about what the report should run for and where it should go.


Cheers
Post #1464395
Posted Monday, June 17, 2013 7:55 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Sunday, July 20, 2014 9:06 PM
Points: 2,693, Visits: 1,202
jfogel (6/17/2013)
philcart (7/6/2011)
Firstly, I'd ask what is behind the requirement to run the subscription using T-SQL? That really defeats the purpose of setting up the subscription in the first place. When you create a subscription you're saying "run this report, with these parameter values, at this time".


Lack of a version other than Standard is the most likely cause. If you have a single report that has to be run for 10-20 "groups" via a different value for a parameter you you find yourself in the position the OP is or was in. I'm facing the same thing and I don't want to write a web-based front end because we already have something like that to setup all the details about what the report should run for and where it should go.


Rendering the reports via the web service isn't a "web-based front end". Generally it's a console application that calls the appropriate methods as shown in the example url I posted.

If your requirement is to render and distribute, not display, the reports, then the web service is what you should be using.


Hope this helps
Phill Carter
--------------------
Colt 45 - the original point and click interface

Australian SQL Server User Groups - My profile
Phills Philosophies
Murrumbeena Cricket Club
Post #1464435
Posted Monday, June 17, 2013 8:37 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, July 24, 2014 7:43 AM
Points: 371, Visits: 954
I'll check it out. Right now I'm thinking of a different method but I really don't want to close the door to other and possibly better options.

Cheers
Post #1464440
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse