johnnyg123
asked on
SSRS info Query
I found this handy script that lists great information about ssrs reports
CREATE PROC sp_HelpSSRSReport
@ReportName NVARCHAR(850)
,@ShowExecutionLog bit = 0
AS
Declare @Namespace NVARCHAR(500)
Declare @SQL VARCHAR(max)
SELECT @Namespace= SUBSTRING(
x.CatContent
,x.CIndex
,CHARINDEX('"',x.CatConten t,x.CIndex +7) - x.CIndex
)
FROM
(
SELECT CatContent = CONVERT(NVARCHAR(MAX),CONV ERT(XML,CO NVERT(VARB INARY(MAX) ,C.Content )))
,CIndex = CHARINDEX('xmlns="',CONVER T(NVARCHAR (MAX),CONV ERT(XML,CO NVERT(VARB INARY(MAX) ,C.Content ))))
FROM Reportserver.dbo.Catalog C
WHERE C.Content is not null
AND C.Type = 2
) X
SELECT @Namespace = REPLACE(@Namespace,'xmlns= "','') + ''
SELECT Name,CreatedBy = U.UserName
,CreationDate = C.CreationDate
,ModifiedBy = UM.UserName
,ModifiedDate
FROM Reportserver.dbo.Catalog C
JOIN Reportserver.dbo.Users U
ON C.CreatedByID = U.UserID
JOIN Reportserver.dbo.Users UM
ON c.ModifiedByID = UM.UserID
WHERE Name = @ReportName
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
-- Get parameters of the report
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
SELECT Name = Paravalue.value('Name[1]', 'VARCHAR(250)')
,Type = Paravalue.value('Type[1]', 'VARCHAR(250)')
,Nullable = Paravalue.value('Nullable[ 1]', 'VARCHAR(250)')
,AllowBlank = Paravalue.value('AllowBlan k[1]', 'VARCHAR(250)')
,MultiValue = Paravalue.value('MultiValu e[1]', 'VARCHAR(250)')
,UsedInQuery = Paravalue.value('UsedInQue ry[1]', 'VARCHAR(250)')
,Prompt = Paravalue.value('Prompt[1] ', 'VARCHAR(250)')
,DynamicPrompt = Paravalue.value('DynamicPr ompt[1]', 'VARCHAR(250)')
,PromptUser = Paravalue.value('PromptUse r[1]', 'VARCHAR(250)')
,State = Paravalue.value('State[1]' , 'VARCHAR(250)')
FROM (
SELECT C.Name,CONVERT(XML,C.Param eter) AS ParameterXML
FROM ReportServer.dbo.Catalog C
WHERE C.Content is not null
AND C.Type = 2
AND C.Name = @ReportName
) a
CROSS APPLY ParameterXML.nodes('//Para meters/Par ameter') p ( Paravalue )
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
-- Get Datasources Associated with the report
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
SELECT @SQL = 'WITH XMLNAMESPACES ( DEFAULT ''' + @Namespace +''', ''http://schemas.microsoft.com/SQLServer/reporting/reportdesigner'' AS rd )
SELECT ReportName = name
,DataSourceName = x.value(''(@Name)[1]'', ''VARCHAR(250)'')
,DataProvider = x.value(''(ConnectionPrope rties/Data Provider)[ 1]'',''VAR CHAR(250)' ')
,ConnectionString = x.value(''(ConnectionPrope rties/Conn ectString) [1]'',''VA RCHAR(250) '')
FROM ( SELECT C.Name,CONVERT(XML,CONVERT (VARBINARY (MAX),C.Co ntent)) AS reportXML
FROM ReportServer.dbo.Catalog C
WHERE C.Content is not null
AND C.Type = 2
AND C.Name = ''' + @ReportName + '''
) a
CROSS APPLY reportXML.nodes(''/Report/ DataSource s/DataSour ce'') r ( x )
ORDER BY name ;'
EXEC(@SQL)
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
-- Get Data Sets , Command , Data fields Associated with the report
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
SELECT @SQL = 'WITH XMLNAMESPACES ( DEFAULT ''' + @Namespace + ''', ''http://schemas.microsoft.com/SQLServer/reporting/reportdesigner'' AS rd )
SELECT ReportName = name
,DataSetName = x.value(''(@Name)[1]'', ''VARCHAR(250)'')
,DataSourceName = x.value(''(Query/DataSourc eName)[1]' ',''VARCHA R(250)'')
,CommandText = x.value(''(Query/CommandTe xt)[1]'',' 'VARCHAR(2 50)'')
,Fields = df.value(''(@Name)[1]'','' VARCHAR(25 0)'')
,DataField = df.value(''(DataField)[1]' ',''VARCHA R(250)'')
,DataType = df.value(''(rd:TypeName)[1 ]'',''VARC HAR(250)'' )
FROM ( SELECT C.Name,CONVERT(XML,CONVERT (VARBINARY (MAX),C.Co ntent)) AS reportXML
FROM ReportServer.dbo.Catalog C
WHERE C.Content is not null
AND C.Type = 2
AND C.Name = ''' + @ReportName + '''
) a
CROSS APPLY reportXML.nodes(''/Report/ DataSets/D ataSet'') r ( x )
CROSS APPLY x.nodes(''Fields/Field'') f(df)
ORDER BY name '
EXEC(@SQL)
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
-- Get subscription Associated with the report
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
SELECT Reportname = c.Name
,SubscriptionDesc=su.Descr iption
,Subscriptiontype=su.Event Type
,su.LastStatus
,su.LastRunTime
,Schedulename=sch.Name
,ScheduleType = sch.EventType
,ScheduleFrequency =
CASE sch.RecurrenceType
WHEN 1 THEN 'Once'
WHEN 2 THEN 'Hourly'
WHEN 4 THEN 'Daily/Weekly'
WHEN 5 THEN 'Monthly'
END
,su.Parameters
FROM Reportserver.dbo.Subscript ions su
JOIN Reportserver.dbo.Catalog c
ON su.Report_OID = c.ItemID
JOIN Reportserver.dbo.ReportSch edule rsc
ON rsc.ReportID = c.ItemID
AND rsc.SubscriptionID = su.SubscriptionID
JOIN Reportserver.dbo.Schedule Sch
ON rsc.ScheduleID = sch.ScheduleID
WHERE c.Name = @ReportName
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
-- Get Snapshot associated with the report
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
SELECT C.Name
,H.SnapshotDate
,S.Description
,ScheduleForSnapshot = ISNULL(Sc.Name,'No Schedule available for Snapshot')
,ScheduleType = sc.EventType
,ScheduleFrequency =
CASE sc.RecurrenceType
WHEN 1 THEN 'Once'
WHEN 2 THEN 'Hourly'
WHEN 4 THEN 'Daily/Weekly'
WHEN 5 THEN 'Monthly'
END
,sc.LastRunTime
,sc.LastRunStatus
,ScheduleNextRuntime = SC.NextRunTime
,S.EffectiveParams
,S.QueryParams
FROM Reportserver.dbo.History H
JOIN Reportserver.dbo.SnapshotD ata S
ON H.SnapshotDataID = S.SnapshotDataID
JOIN Reportserver.dbo.Catalog c
ON C.ItemID = H.ReportID
LEFT JOIN Reportserver.dbo.ReportSch edule Rs
ON RS.ReportID = H.ReportID
AND RS.ReportAction = 2
LEFT JOIN Reportserver.dbo.Schedule Sc
ON Sc.ScheduleID = rs.ScheduleID
WHERE C.Name = @ReportName
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
-- Get Users List having access to reports and tasks they can perform on the report
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
SELECT C.Name
,U.UserName
,R.RoleName
,R.Description
,U.AuthType
FROM Reportserver.dbo.Users U
JOIN Reportserver.dbo.PolicyUse rRole PUR
ON U.UserID = PUR.UserID
JOIN Reportserver.dbo.Policies P
ON P.PolicyID = PUR.PolicyID
JOIN Reportserver.dbo.Roles R
ON R.RoleID = PUR.RoleID
JOIN Reportserver.dbo.Catalog c
ON C.PolicyID = P.PolicyID
WHERE c.Name = @ReportName
ORDER BY U.UserName
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
-- Execution Log fo the report
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
If @ShowExecutionLog = 1
SELECT C.Name
,Case E.Requesttype
WHEN 1 THEN 'Subscription'
WHEN 0 THEN 'Report Launch'
ELSE ''
END
,E.TimeStart
,E.TimeProcessing
,E.TimeRendering
,E.TimeEnd
,E.Status
,E.InstanceName
,E.UserName
FROM Reportserver.dbo.Execution Log E
JOIN Reportserver.dbo.Catalog C
ON E.ReportID = C.ItemID
WHERE C.Name = @ReportName
ORDER BY E.TimeStart DESC
I'd like to modify it so that it will return this information for all reports instead of having to run one report at a time (i.e. make it so don't need @reportname parameter) but not sure how
CREATE PROC sp_HelpSSRSReport
@ReportName NVARCHAR(850)
,@ShowExecutionLog bit = 0
AS
Declare @Namespace NVARCHAR(500)
Declare @SQL VARCHAR(max)
SELECT @Namespace= SUBSTRING(
x.CatContent
,x.CIndex
,CHARINDEX('"',x.CatConten
)
FROM
(
SELECT CatContent = CONVERT(NVARCHAR(MAX),CONV
,CIndex = CHARINDEX('xmlns="',CONVER
FROM Reportserver.dbo.Catalog C
WHERE C.Content is not null
AND C.Type = 2
) X
SELECT @Namespace = REPLACE(@Namespace,'xmlns=
SELECT Name,CreatedBy = U.UserName
,CreationDate = C.CreationDate
,ModifiedBy = UM.UserName
,ModifiedDate
FROM Reportserver.dbo.Catalog C
JOIN Reportserver.dbo.Users U
ON C.CreatedByID = U.UserID
JOIN Reportserver.dbo.Users UM
ON c.ModifiedByID = UM.UserID
WHERE Name = @ReportName
--------------------------
-- Get parameters of the report
--------------------------
SELECT Name = Paravalue.value('Name[1]',
,Type = Paravalue.value('Type[1]',
,Nullable = Paravalue.value('Nullable[
,AllowBlank = Paravalue.value('AllowBlan
,MultiValue = Paravalue.value('MultiValu
,UsedInQuery = Paravalue.value('UsedInQue
,Prompt = Paravalue.value('Prompt[1]
,DynamicPrompt = Paravalue.value('DynamicPr
,PromptUser = Paravalue.value('PromptUse
,State = Paravalue.value('State[1]'
FROM (
SELECT C.Name,CONVERT(XML,C.Param
FROM ReportServer.dbo.Catalog C
WHERE C.Content is not null
AND C.Type = 2
AND C.Name = @ReportName
) a
CROSS APPLY ParameterXML.nodes('//Para
--------------------------
-- Get Datasources Associated with the report
--------------------------
SELECT @SQL = 'WITH XMLNAMESPACES ( DEFAULT ''' + @Namespace +''', ''http://schemas.microsoft.com/SQLServer/reporting/reportdesigner'' AS rd )
SELECT ReportName = name
,DataSourceName = x.value(''(@Name)[1]'', ''VARCHAR(250)'')
,DataProvider = x.value(''(ConnectionPrope
,ConnectionString = x.value(''(ConnectionPrope
FROM ( SELECT C.Name,CONVERT(XML,CONVERT
FROM ReportServer.dbo.Catalog C
WHERE C.Content is not null
AND C.Type = 2
AND C.Name = ''' + @ReportName + '''
) a
CROSS APPLY reportXML.nodes(''/Report/
ORDER BY name ;'
EXEC(@SQL)
--------------------------
-- Get Data Sets , Command , Data fields Associated with the report
--------------------------
SELECT @SQL = 'WITH XMLNAMESPACES ( DEFAULT ''' + @Namespace + ''', ''http://schemas.microsoft.com/SQLServer/reporting/reportdesigner'' AS rd )
SELECT ReportName = name
,DataSetName = x.value(''(@Name)[1]'', ''VARCHAR(250)'')
,DataSourceName = x.value(''(Query/DataSourc
,CommandText = x.value(''(Query/CommandTe
,Fields = df.value(''(@Name)[1]'',''
,DataField = df.value(''(DataField)[1]'
,DataType = df.value(''(rd:TypeName)[1
FROM ( SELECT C.Name,CONVERT(XML,CONVERT
FROM ReportServer.dbo.Catalog C
WHERE C.Content is not null
AND C.Type = 2
AND C.Name = ''' + @ReportName + '''
) a
CROSS APPLY reportXML.nodes(''/Report/
CROSS APPLY x.nodes(''Fields/Field'') f(df)
ORDER BY name '
EXEC(@SQL)
--------------------------
-- Get subscription Associated with the report
--------------------------
SELECT Reportname = c.Name
,SubscriptionDesc=su.Descr
,Subscriptiontype=su.Event
,su.LastStatus
,su.LastRunTime
,Schedulename=sch.Name
,ScheduleType = sch.EventType
,ScheduleFrequency =
CASE sch.RecurrenceType
WHEN 1 THEN 'Once'
WHEN 2 THEN 'Hourly'
WHEN 4 THEN 'Daily/Weekly'
WHEN 5 THEN 'Monthly'
END
,su.Parameters
FROM Reportserver.dbo.Subscript
JOIN Reportserver.dbo.Catalog c
ON su.Report_OID = c.ItemID
JOIN Reportserver.dbo.ReportSch
ON rsc.ReportID = c.ItemID
AND rsc.SubscriptionID = su.SubscriptionID
JOIN Reportserver.dbo.Schedule Sch
ON rsc.ScheduleID = sch.ScheduleID
WHERE c.Name = @ReportName
--------------------------
-- Get Snapshot associated with the report
--------------------------
SELECT C.Name
,H.SnapshotDate
,S.Description
,ScheduleForSnapshot = ISNULL(Sc.Name,'No Schedule available for Snapshot')
,ScheduleType = sc.EventType
,ScheduleFrequency =
CASE sc.RecurrenceType
WHEN 1 THEN 'Once'
WHEN 2 THEN 'Hourly'
WHEN 4 THEN 'Daily/Weekly'
WHEN 5 THEN 'Monthly'
END
,sc.LastRunTime
,sc.LastRunStatus
,ScheduleNextRuntime = SC.NextRunTime
,S.EffectiveParams
,S.QueryParams
FROM Reportserver.dbo.History H
JOIN Reportserver.dbo.SnapshotD
ON H.SnapshotDataID = S.SnapshotDataID
JOIN Reportserver.dbo.Catalog c
ON C.ItemID = H.ReportID
LEFT JOIN Reportserver.dbo.ReportSch
ON RS.ReportID = H.ReportID
AND RS.ReportAction = 2
LEFT JOIN Reportserver.dbo.Schedule Sc
ON Sc.ScheduleID = rs.ScheduleID
WHERE C.Name = @ReportName
--------------------------
-- Get Users List having access to reports and tasks they can perform on the report
--------------------------
SELECT C.Name
,U.UserName
,R.RoleName
,R.Description
,U.AuthType
FROM Reportserver.dbo.Users U
JOIN Reportserver.dbo.PolicyUse
ON U.UserID = PUR.UserID
JOIN Reportserver.dbo.Policies P
ON P.PolicyID = PUR.PolicyID
JOIN Reportserver.dbo.Roles R
ON R.RoleID = PUR.RoleID
JOIN Reportserver.dbo.Catalog c
ON C.PolicyID = P.PolicyID
WHERE c.Name = @ReportName
ORDER BY U.UserName
--------------------------
-- Execution Log fo the report
--------------------------
If @ShowExecutionLog = 1
SELECT C.Name
,Case E.Requesttype
WHEN 1 THEN 'Subscription'
WHEN 0 THEN 'Report Launch'
ELSE ''
END
,E.TimeStart
,E.TimeProcessing
,E.TimeRendering
,E.TimeEnd
,E.Status
,E.InstanceName
,E.UserName
FROM Reportserver.dbo.Execution
JOIN Reportserver.dbo.Catalog C
ON E.ReportID = C.ItemID
WHERE C.Name = @ReportName
ORDER BY E.TimeStart DESC
I'd like to modify it so that it will return this information for all reports instead of having to run one report at a time (i.e. make it so don't need @reportname parameter) but not sure how
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.