Query SSRS Report Content

Bret Stateham has a detailed post about how to query SSRS RDL definition.

Here is the the link to the post:

Extracting SSRS Report RDL (XML) from the ReportServer database


Here is code snippet I copied from the post for how to query the content for a search word:


--The first CTE gets the content as a varbinary(max)
--as well as the other important columns for all reports,
--data sources and shared datasets.
;WITH ItemContentBinaries AS
    ,CASE Type
       WHEN 2 THEN 'Report'
       WHEN 5 THEN 'Data Source'
       WHEN 7 THEN 'Report Part'
       WHEN 8 THEN 'Shared Dataset'
       ELSE 'Other'
     END AS TypeDescription
    ,CONVERT(varbinary(max),Content) AS Content
  FROM myReportServer.dbo.Catalog
  WHERE Type IN (2,5,7,8)
--The second CTE strips off the BOM if it exists...
ItemContentNoBOM AS
       WHEN LEFT(Content,3) = 0xEFBBBF
         THEN CONVERT(varbinary(max),SUBSTRING(Content,4,LEN(Content)))
     END AS Content
  FROM ItemContentBinaries
--The old outer query is now a CTE to get the content in its xml form only...
,ItemContentXML AS
    ,CONVERT(xml,Content) AS ContentXML
 FROM ItemContentNoBOM
--now use the XML data type to extract the queries, and their command types and text....
,finalCTEForQuery as (
    ,ISNULL(Query.value('(./*:CommandType/text())[1]','nvarchar(1024)'),'Query') AS CommandType
    ,Query.value('(./*:CommandText/text())[1]','nvarchar(max)') AS CommandText
FROM ItemContentXML
--Get all the Query elements (The "*:" ignores any xml namespaces)
CROSS APPLY ItemContentXML.ContentXML.nodes('//*:Query') Queries(Query)

Select * from finalCTEForQuery
Where CommandText Like '%searchWord%'


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s