使用 T-SQL 查找与 SSRS 报告关联的存储过程

Eli*_*eth 2 t-sql sql-server stored-procedures reporting-services

我在编写这个查询时得到了一些帮助——我有点不知所措,因为我试图找到所使用的查询类型或过程,并且我不确定还要向查询中添加什么或如何更改它。

SELECT      
    Ds.Name as Data_Source_Name,
    C2.Name AS Data_Source_Reference_Name,
    C.Name AS Dependent_Item_Name,
    C.Path AS Dependent_Item_Path,
    ds.*
FROM
    ReportServer.dbo.DataSource AS DS
INNER JOIN  
    ReportServer.dbo.Catalog AS C ON DS.ItemID = C.ItemID 
                                  AND DS.Link IN (SELECT ItemID 
                                                  FROM ReportServer.dbo.Catalog
                                                  WHERE Type = 5) --Type 5 identifies data sources
FULL OUTER JOIN 
    ReportServer.dbo.Catalog C2 ON DS.Link = C2.ItemID
WHERE
    C2.Type = 5
    AND c.name LIKE '%mkt%'
ORDER BY    
    C.Path, C2.Name ASC, C.Name ASC;
Run Code Online (Sandbox Code Playgroud)

请指教。

在此输入图像描述

Tim*_*ott 5

根据我的评论,尝试一下,应该会让您朝着正确的方向前进,了解如何解析 xml 并将特定命令归零。

您可能需要更新下面脚本中的名称空间并添加您的报告名称。

但尝试这样的事情:

;WITH XMLNAMESPACES (DEFAULT 'http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition') --You may have to change this based on you SSRS version
SELECT
    [Path],
    Name,
    report_xml.value( '(/Report/DataSources/DataSource/@Name)[1]', 'VARCHAR(50)' ) AS DataSource,
    report_xml.value( '(/Report/DataSets/DataSet/Query/CommandText/text())[1]', 'VARCHAR(MAX)' ) AS CommandText, 
    report_xml.value( '(/Report/DataSets/DataSet/Query/CommandType/text())[1]', 'VARCHAR(100)' ) AS CommandType, 
    report_xml
FROM
    (
    SELECT 
        [Path], 
        Name, 
        [Type],
        CAST( CAST( content AS VARBINARY(MAX) ) AS XML ) report_xml 
    FROM dbo.[Catalog]
    WHERE Content IS NOT NULL
    AND [Type] = 2
    ) x
WHERE 
--use below in where clause if searching for the CommandText.  Depending on how the report was developed I would just use the proc name and no brackets or schema.
--Example:  if you report was developed as having [dbo].[procName] just use LIKE '%procName%' below.  Because other reports could just have dbo.procName.
report_xml.value( '(/Report/DataSets/DataSet/Query/CommandText/text())[1]', 'VARCHAR(MAX)' ) LIKE '%Your Proc Name here%'
--comment out the above and uncomment below if know your report name and want to search for that specific report.
--[x].[Name] = 'The Name Of Your Report'
Run Code Online (Sandbox Code Playgroud)