I have a query (unfinished) that gets generic SysJob/ReportServer information. The only issue I'm having is trying to retrieve the name of the stored procedure a SSRS report uses. I've tried multiple queries but in my current attempt I tried to get the procedure name from the sysjobsteps.command
column, unfortunately it only contains the Subscriptions.SubscriptionID
column, which when tracking back to that table, leads me nowhere as well... Any ideas? Thanks!
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
An example of the data in the "sysjobsteps.command" column:
exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='f3296cc8-79e1-4a99-9723-c1880da25a8d'
SOLUTION (messy, but works):
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