declare @XMLDoc xml = ' <rootnode> <group> <id>1</id> <a...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Skeptics

Q&A for scientific skepticism

-- Enter Query Title
-- Enter Query Description

declare @XMLDoc xml = '
<rootnode>
  <group>
    <id>1</id>
     <anothernode>first string</anothernode>
     <anothernode>second string</anothernode>
  </group>
 <group>
   <id>2</id>
     <anothernode>third string</anothernode>
     <anothernode>fourth string</anothernode>
  </group>
</rootnode>'

SELECT T.N.value('../id[1]', 'int') AS id,
       T.N.value('.', 'varchar(30)') AS anothernode
FROM @XMLDoc.nodes('rootnode/group/anothernode') AS T(N)

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results