title: How to read this XML in the below mentioned format - SQL Server 2012
body: <p>Any help would be greatly appreciated! Trying to transform the below XML into table structure in SQL Server.</p>
  
  <pre><code>&lt;SearchKey EntityType="2" userid="12" QName="search1"&gt;
      &lt;Groups&gt;
          &lt;Group seq="1"&gt;
              &lt;GroupID&gt;1&lt;/GroupID&gt;
              &lt;Column seq="1"&gt;2&lt;/Column&gt;
              &lt;Column seq="2"&gt;3&lt;/Column&gt;
          &lt;/Group&gt;
          &lt;Group seq="2"&gt;
              &lt;GroupID&gt;2&lt;/GroupID&gt;
              &lt;Column seq="1"&gt;1&lt;/Column&gt;
              &lt;Column seq="2"&gt;2&lt;/Column&gt;
          &lt;/Group&gt;
          &lt;Group seq="3"&gt;
              &lt;GroupID&gt;3&lt;/GroupID&gt;
              &lt;Group seq="1"&gt;1&lt;/Group&gt;
              &lt;Column seq="2"&gt;2&lt;/Column&gt;
          &lt;/Group&gt;
          &lt;Group seq="4"&gt;
              &lt;GroupID&gt;4&lt;/GroupID&gt;
              &lt;Group seq="1"&gt;1&lt;/Group&gt;
              &lt;Group seq="2"&gt;2&lt;/Group&gt;
              &lt;Column seq="3"&gt;3&lt;/Column&gt;
          &lt;/Group&gt;
      &lt;/Groups&gt;
  &lt;/SearchKey&gt;
  </code></pre>
  
  <p>Tried reading the XML with the below code, but the expected output is not achieved. Please help!</p>
  
  <pre><code>SELECT a.b.value('GroupID[1]', 'varchar(10)') AS GroupID
      ,a.b.value('Column[1]', 'varchar(10)') AS ColumnSeq
      ,a.b.value('GroupID[1]', 'varchar(10)') AS GroupID1
  FROM @XMLString.nodes('/Groups/Group') a(b)
  </code></pre>
  
  <p>In this below table format:</p>
  
  <pre><code>GroupID SeqID   ColumnValue ChildGroupID
  1       1       2           NULL
  1       2       3           NULL
  3       1       NULL        1
  3       2       2           NULL
  4       1       NULL        1
  4       2       NULL        2
  4       3       3           NULL
  </code></pre>
  
  <p>Also tried the below code, but not able to retrieve records in the above format:</p>
  
  <pre><code>SELECT a.b.value('GroupID[1]', 'varchar(10)') AS GroupID
      ,a.b.value('(@GrpSeq)[1]', 'varchar(50)')  AS GrpSeq
      ,a.b.value('(GroupID)[1]', 'varchar(50)')  AS GroupID
      ,a.b.value('(Column/@ColSeq)[1]', 'varchar(50)') AS ColSeq
  FROM @XMLString.nodes('SearchKey/Groups/Group') a(b)
  </code></pre>
  
  <p>Thanks for the all the help :)</p>