Presentation is loading. Please wait.

Presentation is loading. Please wait.

Surviving parsing XML with T-SQL

Similar presentations


Presentation on theme: "Surviving parsing XML with T-SQL"— Presentation transcript:

1 Surviving parsing XML with T-SQL
Steve Simon MVP SQL Server BI

2 SQL Server MVP Atrion Networking Corporation (Providence RI) Involved with database design for 29 years + Presenter at numerous PASS summits. Presenter at numerous SQL Saturday events. Presented at Copenhagen Nordic Rally in March. Regular contributor on SQLShack.com

3 Facts of life Data is not always stored in a simple format.
Often data is imported from xml documents. Murphy’s law states that the data will be at the bottom of the tree. Parsing data from the tree is CPU consuming.

4 Today’s challenge We need a list of reports that have been run over the past 60 days. We need the name of the report. We need the dataset and data source name. We need the fields that are displayed in the report.

5 Let’s get started

6 A practical case Conversion of warehouse reports to run off of “Service Now”. Which reports are still active? Who has used them and when? Will the tables in “Service Now” contain the necessary fields?

7

8 All of our data resides in the Report Server Database

9

10 Selecting the Schema via a CTE
;WITH XMLNAMESPACES (DEFAULT ' ,' AS rd)

11 We shall be utilizing two tables
dbo.Catalog dbo.ExecutionLogStorage

12 We execute the CTE

13 We convert the content field to XML

14 FROM (SELECT RPT.Path AS ReportPath
,RPT.name AS ReportName ,CONVERT(xml, CONVERT(varbinary(max), RPT.content)) AS contentXML FROM [SQLSaturday386Albany].dbo.[Catalog] AS RPT INNER JOIN [SQLSaturday386Albany].dbo.ExecutionLogStorage Storage ON RPT.ItemID = Storage.ReportID WHERE RPT.Type = 2 –-i.e. a Report ) AS RPT

15 Content XML contains the ‘result set’

16

17 XML containing the field names

18 Type definitions

19 Cross Apply to get down the different branches of the tree

20 Ascertaining the Dataset and Data Source Names

21 Fields within our reports

22 Data source, dataset and parameters passed

23 The query is also available from the report

24 Demo 1

25 Reporting

26

27 Demo 2

28 Take-Away

29 Why battle with XML Parsing and processing XML data feeds.
Understanding the tree structure helps with coding. Techniques may be applied to reporting. Getting access to critical data.

30 Surviving parsing XML with T-SQL
Steve Simon MVP SQL Server BI


Download ppt "Surviving parsing XML with T-SQL"

Similar presentations


Ads by Google