Last active
August 13, 2018 14:04
-
-
Save mbourgon/5876421 to your computer and use it in GitHub Desktop.
For SQL Server Reporting Services (SSRS), this will look in your SSRS catalog (in ReportServer) and pull out information like DataSource, Data Set Name, and the actual SQL running therein. thebakingdba.blogspot.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Version 1.01 - 2013/06/27 mbourgon thebakingdba.blogspot.com | |
Purpose: Look through the RDLs stored in your SSRS server (ReportServer DB), returning info like the Datasource and Query. | |
This version doesn't contain the DataSource. 1.1 or 1.2 will, since it can be stored in 2 different places. | |
Getting the RDL cribbed from http://markvsql.com/2009/11/find-all-deployed-ssrs-reports-that-reference-a-particular-field/ | |
XML query from Mikael Eriksson on StackOverflow http://stackoverflow.com/questions/17332257/sql-query-xml-while-ignoring-namespace | |
(the trick is ignoring the namespace, which led me to this non-normal [for me anyway] syntax) Thanks Mikael! | |
1.00 - first revision - it's alive! | |
1.01 - adding ORDER BY | |
*/ | |
; | |
WITH cte | |
AS ( | |
--gets the RDL; note the double convert. | |
SELECT [path], [name] AS Report_Name, | |
CONVERT(XML, CONVERT(VARBINARY(MAX), content)) AS rdl | |
FROM reportserver.dbo.catalog | |
) | |
SELECT LEFT([Path], LEN([path]) - CHARINDEX('/',REVERSE([Path])) + 1) AS Report_Path, | |
Report_Name, | |
T1.N.value('@Name', 'nvarchar(128)') AS DataSetName, | |
T2.N.value('(*:DataSourceName/text())[1]', 'nvarchar(128)') AS DataSourceName, | |
ISNULL(T2.N.value('(*:CommandType/text())[1]', 'nvarchar(128)'), 'T-SQL') AS CommandType, | |
T2.N.value('(*:CommandText/text())[1]', 'nvarchar(max)') AS CommandText | |
FROM cte AS T | |
CROSS APPLY T.rdl.nodes('/*:Report/*:DataSets/*:DataSet') AS T1 (N) | |
CROSS APPLY T1.N.nodes('*:Query') AS T2 (N) | |
ORDER BY Report_Path, Report_Name, DataSetName, DataSourceName, CommandType, CommandText |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment