I am trying to query the SSRS XML Catalog for those SSRS Reports which have subreports, and to list each of those subreports with their parent report - in the following format:
Parent Report SubReport
Parent Report SubReport2
etc.
This is my code so far, but I'm not certain where to put the filters and filter syntax on the XML Query portion:
Drop TABLE prmcustomreports.dbo.tblReportDefinition1 CREATE TABLE prmcustomreports.dbo.tblReportDefinition1 ( [rowid] [int] IDENTITY(1,1) NOT NULL, Servername varchar(255) default @@ServerName, Ver varchar(max) default @@Version, report_name varchar (max), report_path varchar (max), Report_N2 varchar (max), DataSource varchar (max), ContentXML XML, LastUpdatedDate datetime DEFAULT (getdate()) , Element varchar(max), Attribute varchar(max), Val varchar(max), CONSTRAINT [tblPKReportDefinition1] PRIMARY KEY CLUSTERED ( [ROWid] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] Drop TABLE prmcustomreports.dbo.tblReportDefinition2 CREATE TABLE prmcustomreports.dbo.tblReportDefinition2 ( [rowid] [int] IDENTITY(1,1) NOT NULL, Servername varchar(255) default @@ServerName, Ver varchar(max) default @@Version, report_name varchar (max), report_path varchar (max), Report_N2 varchar (max), DataSource varchar (max), ContentXML XML, LastUpdatedDate datetime DEFAULT (getdate()) , Element varchar(max), Attribute varchar(max), Val varchar(max), CONSTRAINT [tblPKReportDefinition2] PRIMARY KEY CLUSTERED ( [ROWid] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] Truncate table prmcustomreports.dbo.tblReportDefinition1 Truncate table prmcustomreports.dbo.tblReportDefinition2 Insert into prmcustomreports.dbo.tblReportDefinition1 ( report_name , report_path , Report_N2 , DataSource, ContentXML ) SELECT c.[Name], c.[Path], d.Name, cd.path AS [Data Source], CONVERT(varchar(max), CONVERT(varbinary(max), C.[Content])) Content FROM [dbo].[Catalog] (nolock) c LEFT JOIN dbo.DataSource (nolock) d ON c.ItemID = d.ItemID LEFT JOIN [dbo].[Catalog] (nolock) cd ON d.link = cd.ItemID WHERE (c.[Type] = 2 OR c.[Type] = 6 or c.[Type] = 5) AND LEN(c.Name) <> 0 ORDER BY c.[Name], c.[Path] --Select * from #ReportDefinition Insert into prmcustomreports.dbo.tblReportDefinition2 ( report_name , report_path , Report_N2 , DataSource, ContentXML, Element , Attribute, Val ) SELECT report_name , report_path , Report_N2 , DataSource, ContentXML, x.y.value('local-name(..)', 'VARCHAR(MAX)') parentElementName, x.y.value('local-name(.)', 'VARCHAR(MAX)') as attribute, x.y.value('.', 'VARCHAR(MAX)') as val FROM PRMCustomReports..tblReportDefinition1 rd CROSS APPLY rd.ContentXML.nodes('//*[text()], //@*') AS x(y)
John