Created
December 3, 2015 20:57
-
-
Save samueleresca/82a3e850716ecb164ed4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
-- ============================================= | |
-- Author:Resca Samuele | |
-- Description: Returns names of stored procedure that are used in report | |
-- ============================================= | |
CREATE PROCEDURE [dbo].[ReportSPROCDependencies] | |
@ReportName nvarchar(MAX) = NULL | |
AS | |
BEGIN | |
SET NOCOUNT ON; | |
;WITH XMLNAMESPACES ( | |
DEFAULT | |
--IMPORTANT(!) There are different namespaces for every version of Sql server. | |
'http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition', | |
'http://schemas.microsoft.com/SQLServer/reporting/reportdesigner' AS rd | |
) | |
SELECT DISTINCT | |
Name, | |
Path, | |
xmldoc.VALUE('CommandType[1]', 'VARCHAR(50)') AS CommandType, | |
xmldoc.VALUE('CommandText[1]','VARCHAR(100)') AS StoredProcedreName | |
FROM ( | |
SELECT name, path, | |
CAST(CAST(content AS VARBINARY(MAX)) AS XML) AS reportXML | |
FROM ReportServer.dbo.Catalog | |
) tmp | |
CROSS APPLY reportXML.nodes('/Report/DataSets/DataSet/Query') r(xmldoc) | |
WHERE xmldoc.VALUE('CommandType[1]', 'VARCHAR(50)') = 'StoredProcedure' | |
AND (@ReportName LIKE '%'+@ReportName+'%' OR @ReportName IS NULL) | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment