SQL to query datasets with command text for all SSRS reports


-- Transact-SQL to query datasets with command text for all SSRS reports.
/*
This Transact-SQL script list for all SSRS reports the used datasources and datasets with the command text.
Requires select permissions on the ReportServer database.
*/
-- List datasets with command text for all SSRS reports
;WITH
 XMLNAMESPACES
     (DEFAULT 'http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition'
             ,'http://schemas.microsoft.com/sqlserver/reporting/reportdesigner'
      AS rd)
,DEF AS
    (SELECT RPT.ReportPath
           ,R.RptNode.value('(./Query/DataSourceName)[1]', 'nvarchar(425)') AS DataSourceName
           ,R.RptNode.value('@Name[1]', 'nvarchar(425)') AS DataSetName
           ,REPLACE(REPLACE(LTRIM((R.RptNode.value('(./Query/CommandText)[1]', 'nvarchar(4000)')))
                    ,'>', '>')
                    ,'&lt;', '<')
            AS CommandText
     FROM (SELECT RPT.Path AS ReportPath
                 ,RPT.name AS ReportName
                 ,CONVERT(xml, CONVERT(varbinary(max), RPT.content)) AS contentXML
           FROM ReportServer.dbo.[Catalog] AS RPT
           WHERE RPT.Type = 2  -- 2 = Reports
         ) AS RPT
     CROSS APPLY RPT.contentXML.nodes('/Report/DataSets/DataSet') AS R(RptNode)
    )
SELECT DEF.ReportPath
      ,DEF.DataSourceName
      ,DEF.DataSetName
      ,DEF.CommandText
FROM DEF
-- Optional filter:
-- WHERE DEF.CommandText LIKE '%/[Team System/]%' -- MDX query against TFS cube
ORDER BY DEF.ReportPath
        ,DEF.DataSourceName
        ,DEF.DataSetName

Comments


  1. Through this post, I know that your good knowledge in playing with all the pieces was very helpful. I notify that this is the first place where I find issues I've been searching for. You have a clever yet attractive way of writing on Msbi online training

    ReplyDelete
  2. Great article with very unique content.
    Thank you...

    MSBI Online Training India

    ReplyDelete

Post a Comment

Hi User,
Thanks for visiting My Blog and please provide your valuable feedback and subscribe for more updates. Please don't post any spam content or comments.
Thank You

Popular Posts

Failed to execute the package or element. Build errors were encountered

Exception deserializing the package "The process cannot access the file because it is being used by another process."

Temporary enable and disable SSRS subscriptions