SSMS / SSRS-从查询中获取SSRS数据集使用的存储过程名称

时间:2018-12-26 16:01:57

标签: sql-server tsql reporting-services ssms

我有一个查询(未完成),该查询获取通用的SysJob / ReportServer信息。我遇到的唯一问题是尝试检索SSRS报告使用的存储过程的名称。我已经尝试了多个查询,但是在当前尝试中,我尝试从sysjobsteps.command列中获取过程名称,但是不幸的是,它仅包含Subscriptions.SubscriptionID列,当回溯到该表时,它无处可寻还有...有什么想法吗?谢谢!

SELECT JOBS.Name AS [JobName(ID)]
    , CAT.Name AS [CatName] 
    , SCH.SubscriptionID,
    , SUB.LastRunTime
    , STEPS.command -- @eventData = ReportSchedule.SubscriptionID
FROM msdb.dbo.sysjobs JOBS
    INNER JOIN msdb.dbo.sysjobsteps STEPS ON JOBS.job_id = STEPS.job_id
    INNER JOIN ReportServer.dbo.ReportSchedule SCH ON JOBS.name = CAST(SCH.ScheduleID AS sysname)
    INNER JOIN ReportServer.dbo.Subscriptions SUB ON SCH.SubscriptionID = SUB.SubscriptionID
    INNER JOIN ReportServer.dbo.Catalog CAT ON SUB.Report_OID = CAT.ItemID
WHERE JOBS.enabled = 1
ORDER BY CAT.Name

“ sysjobsteps.command”列中的数据示例:

exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='f3296cc8-79e1-4a99-9723-c1880da25a8d'

解决方案(混乱,但有效):

SELECT REPLACE(LEFT(SUBSTRING(CAST(CONVERT(xml, CONVERT(varbinary(max), CAT.content)) AS VARCHAR(MAX)),
    CHARINDEX('<CommandText>', CAST(CONVERT(xml, CONVERT(varbinary(max), CAT.content)) AS VARCHAR(MAX))), 150),
    CHARINDEX('</CommandText>', SUBSTRING(CAST(CONVERT(xml, CONVERT(varbinary(max), CAT.content)) AS VARCHAR(MAX)),
    CHARINDEX('<CommandText>', CAST(CONVERT(xml, CONVERT(varbinary(max), CAT.content)) AS VARCHAR(MAX))), 150)) - 1),
    '<CommandText>', '') AS ProcName
FROM ReportServer.dbo.Catalog

1 个答案:

答案 0 :(得分:2)

看看:Query to find list of *all* SSRS DataSets across *all* SSRS reports on ReportServer instance

它的答案之一是关于如何获取共享和嵌入式数据集的一个相当大且记录良好的示例。