I have a table In the given order the data appears Order cases here. Note XML structure. Type = 0 means that the entry type is the address. 5 cards, B1, B2, B3, B4, B5. The sequence I want is to obtain a table of all the leaves in sequence , like this: When the start node This is the XML parsing snippet, but this is just the beginning. [S] Cross applied from [XmlCol Can anyone suggest how to do this in SQL? Try something like this: Some overview: In XML, feature Value should always be quoted It is not very clear in which order you want the value outside the given root tree (in this example, only B 4 is not a part of the beginning of the tree; A; If there were many such values, in many other trees, this is not a desired order, which is not clear) Using a table variable is one more Using complex CTE can be avoided, but I think they I took up to 10 sub-nodes per level; If there are more sub-nodes, then you can change between 0.1 to 0.01, for example S that has 2 columns:
name For ID and one XML column
This table shows a tree data.
S ----- + ----- ----------- name. XmlCol ----- + ---------------- A | & Lt; E & gt; & Lt; BID = 'B1' type = 0 / & gt; BTID = 'D' type = 1 / & gt; BTD = 'B2' type = 0 / & gt; & Lt; / E & gt; D | & Lt; E & gt; & Lt; BID = 'B3' type = 0 / & gt; & Lt; BID = 'G' type = 1 / & gt; & Lt; / E & gt; F | & Lt; E & gt; & Lt; BID = 'B4' type = 0 / & gt; & Lt; / E & gt; G. & Lt; E & gt; & Lt; BID = 'B5' type = 0 / & gt; & Lt; / E & gt;
Type = 1 means that there is a line with the same name in the table, so there is no node and no leaf.
Leaves -------- B1B3B5B2B4
'A'
SELECT [id] = xTree.b.value ('@ id,' varchar (10) ') ]. Nodes ('/ E / B') xTree (B)
Announcement @ source table (Name VARCHAR (10) PRIMAR Y KE, XMLCL XML NOT NULL) DECLARE @Root VARCHAR (10) = 'A' Source value ('A', Convert (XML, '&
No comments:
Post a Comment