查找报表是否正在使用表

时间:2012-08-14 17:46:08

标签: sql sql-server tsql reporting-services ssms

无论如何都要查明报表服务器上的报表是否正在使用某个特定的表?

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

我在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%';

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