0

无论如何要找出报告服务器上的报告是否正在使用特定表?

4

2 回答 2

2
USE ReportServer

DECLARE @TEXTTOSEARCH AS VARCHAR(200)
SET @TEXTTOSEARCH = 'urtableorview'

;WITH XMLNAMESPACES 
(DEFAULT 'http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition',
'http://schemas.microsoft.com/SQLServer/reporting/reportdesigner' AS rd)

SELECT name
    , x.value('CommandType[1]', 'VARCHAR(100)') AS CommandType
    , x.value('CommandText[1]','VARCHAR(MAX)') AS CommandText
    , x.value('DataSourceName[1]','VARCHAR(150)') AS DataSource
FROM (SELECT name, 
    CAST(CAST(content AS VARBINARY(MAX)) AS XML) AS reportXML 
    FROM Catalog 
    WHERE content IS NOT NULL AND type != 3) AS a
CROSS APPLY reportXML.nodes('/Report/DataSets/DataSet/Query') r(x)
WHERE x.value('CommandType[1]', 'VARCHAR(50)') IS NULL
    AND x.value('CommandText[1]','VARCHAR(MAX)') LIKE '%' + @TEXTTOSEARCH + '%'
ORDER BY name
于 2012-10-02T13:47:56.893 回答
2

我在 Ajit Kumar Thakur https://blogs.technet.microsoft.com/dbtechresource/2015/04/04/retrieve-ssrs-report-server-database-information/的 Technet 文章中发现了这个类似但更简单的查询 。

WITH Reports AS 
(   
  SELECT *
    , CONVERT( VARCHAR(MAX), CONVERT(VARBINARY(MAX), Content)) AS ReportContent
  FROM Catalog
)
SELECT Name, [Path] 
FROM Reports
WHERE ReportContent LIKE '%tablename%';

当您需要“识别任何报告中的任何表、过程或函数的依赖关系时,这非常有用。它提取每个报告的 [the] XML 内容,将其转换为 varchar,然后搜索给定的对象 [name]。目录表包含报表服务器中所有 RDL 文件的 XML 内容。

于 2016-09-22T14:51:11.100 回答