0

I have an XML as below stored in a table.

  `<Customer>
     <Name>
     <FName>Mark</FName>
     <MName>A</MName>
     <LName>Antomy</LName>
    </Name>
   <Address>
    <Street>Clare</Street>
   <City>Clarkson</City>
  </Address>
 </Customer> `

I want to select everything except the root node.

 `<Name>
    <FName>Mark</FName>
    <MName>A</MName>
    <LName>Antomy</LName>
 </Name>
<Address>
  <Street>Clare</Street>
  <City>Clarkson</City>
</Address>`

There are two parallel levels below root. I am unable to get them both in a single query. Can it can be achieved through XQuery. Thanks in advance.

Edit : removed an extra enter code here lurking in the xml.

Vaibhav Verma
  • 47
  • 2
  • 11

1 Answers1

1

You can use .query() with a wildcard:

DECLARE @T TABLE (X XML);
INSERT @T (X) VALUES ('<Customer>
     <Name>
     <FName>Mark</FName>`enter code here`
     <MName>A</MName>
     <LName>Antomy</LName>
    </Name>
   <Address>
    <Street>Clare</Street>
   <City>Clarkson</City>
  </Address>
 </Customer>');

 SELECT X.query('/Customer/*')
 FROM   @T;
GarethD
  • 68,045
  • 10
  • 83
  • 123