I am fighting with @x.nodes('...') as I am new to XQuery. I do have the XML variable @x constructed the following way:
CREATE TABLE tab (a int, b int, c int);
GO
INSERT INTO tab (a, b, c) VALUES (1, 11, 111);
INSERT INTO tab (a, b, c) VALUES (2, 22, 222);
INSERT INTO tab (a, b, c) VALUES (3, 33, 333);
INSERT INTO tab (a, b, c) VALUES (4, 44, 444);
GO
DECLARE @x XML = (SELECT * FROM tab FOR XML RAW, TYPE);
When its content is displayed, it looks like:
<row a="1" b="11" c="111" />
<row a="2" b="22" c="222" />
<row a="3" b="33" c="333" />
<row a="4" b="44" c="444" />
i.e. single multiline string. How can shred the single multielement XML value to many single-element value in the destination table? (I am aware of the official nodes() Method (xml Data Type) documentation page, but I am doing something wrong.)
CREATE TABLE tab2 (e XML);
??? ... @x.nodes('//row') ... ???
Thanks, Petr
P.S. The question is loosely related to Service Broker -- how to extract the rows from the XML message?

