7

On my Report Server database all my users' Report Subscriptions are saved as SQL Agent Jobs, as is normal.

If I connect to the Report Server DB and list out the SQL Agent jobs I see a huge list of jobs named as random strings of characters, eg:

000D5787-8802-4CB1-9784-8897C596003F

By a process of trial and error, I have figured out that particular Agent job relates to my "Daily Sales" report, and I'm able to view the Job History, add SQL commands to the code that the Subscription runs, etc.

However, I have hundreds of user reports. I need to be able to tie back the name of the report to the name of the SQL Agent job somehow. Either by getting Report Server to name its subscription jobs more helpfully, or by having some kind of lookup table that I can refer to when I'm scrolling down the list of Jobs.

Any ideas? I've tried looking in the "Subscriptions" table of ReportServer, it does have some ID numbers which look similar, but none of them match the Job names.

Geoff Griswald
  • 937
  • 12
  • 24
  • 1
    it's an awful "design" feature in my opinion. I create all my SSRS schedules as a "one off" run with a random time (likem 21:21 for that day) disable the jobs that SSRS creates and put the SQL from it in my own jobs and steps. – Thom A Aug 23 '19 at 16:08
  • 1
    Check out Harry's solution below, works a treat! – Geoff Griswald Aug 27 '19 at 08:00

1 Answers1

7

Run the following code .. it should give you a list of all the reports with a subscription and what the job names are:

SELECT distinct
sj.[name] AS [Job Name],
rs.SubscriptionID,
c.[Name] AS [Report Name],
c.[Path]


FROM msdb..sysjobs AS sj 

INNER JOIN ReportServer..ReportSchedule AS rs
ON sj.[name] = CAST(rs.ScheduleID AS NVARCHAR(128)) 

INNER JOIN ReportServer..Subscriptions AS su
ON rs.SubscriptionID = su.SubscriptionID

INNER JOIN ReportServer..[Catalog] c
ON su.Report_OID = c.ItemID

you can then trigger the jobs by running the following command:

USE [msdb]
EXEC sp_start_job @job_name = '[Job Name] from above query'
Harry
  • 2,636
  • 1
  • 17
  • 29