简体   繁体   中英

How to link Report Server Subscription SQL Agent Job name to the name of the report it is running

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.

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM