Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's how I do it generically:</p> <p>I shred the source XML via a call such as</p> <pre> <code> DECLARE @xmlEntityList xml SET @xmlEntityList = ' &lt;ArbitrarilyNamedXmlListElement&gt; &lt;ArbitrarilyNamedXmlItemElement&gt;&lt;SomeVeryImportantInteger&gt;1&lt;/SomeVeryImportantInteger&gt;&lt;/ArbitrarilyNamedXmlItemElement&gt; &lt;ArbitrarilyNamedXmlItemElement&gt;&lt;SomeVeryImportantInteger&gt;2&lt;/SomeVeryImportantInteger&gt;&lt;/ArbitrarilyNamedXmlItemElement&gt; &lt;ArbitrarilyNamedXmlItemElement&gt;&lt;SomeVeryImportantInteger&gt;3&lt;/SomeVeryImportantInteger&gt;&lt;/ArbitrarilyNamedXmlItemElement&gt; &lt;/ArbitrarilyNamedXmlListElement&gt; ' DECLARE @tblEntityList TABLE( SomeVeryImportantInteger int ) INSERT @tblEntityList(SomeVeryImportantInteger) SELECT XmlItem.query('//SomeVeryImportantInteger[1]').value('.','int') as SomeVeryImportantInteger FROM [dbo].[tvfShredGetOneColumnedTableOfXmlItems] (@xmlEntityList) </code> </pre> <p>by utilizing the scalar-valued function</p> <pre> <code> /* Example Inputs */ /* DECLARE @xmlListFormat xml SET @xmlListFormat = ' &lt;ArbitrarilyNamedXmlListElement&gt; &lt;ArbitrarilyNamedXmlItemElement&gt;004421UB7&lt;/ArbitrarilyNamedXmlItemElement&gt; &lt;ArbitrarilyNamedXmlItemElement&gt;59020UH24&lt;/ArbitrarilyNamedXmlItemElement&gt; &lt;ArbitrarilyNamedXmlItemElement&gt;542514NA8&lt;/ArbitrarilyNamedXmlItemElement&gt; &lt;/ArbitrarilyNamedXmlListElement&gt; ' declare @tblResults TABLE ( XmlItem xml ) */ -- ============================================= -- Author: 6eorge Jetson -- Create date: 01/02/3003 -- Description: Shreds a list of XML items conforming to -- the expected generic @xmlListFormat -- ============================================= CREATE FUNCTION [dbo].[tvfShredGetOneColumnedTableOfXmlItems] ( -- Add the parameters for the function here @xmlListFormat xml ) RETURNS @tblResults TABLE ( -- Add the column definitions for the TABLE variable here XmlItem xml ) AS BEGIN -- Fill the table variable with the rows for your result set INSERT @tblResults SELECT tblShredded.colXmlItem.query('.') as XmlItem FROM @xmlListFormat.nodes('/child::*/child::*') as tblShredded(colXmlItem) RETURN END --SELECT * FROM @tblResults </code> </pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload