title: Extracting the name of the root node in XML using SQL
body: <p>From the below table,</p>
  
  <p><a href="https://i.stack.imgur.com/6DzPQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6DzPQ.png" alt="enter image description here"></a></p>
  
  <p>Is there a way to extract the name of the Root node 'Main' alone from the column 'XML_data' using SQL server?</p>
  
  <p>UPDATE:</p>
  
  <pre><code>DECLARE @ProdID int 
  
  create table #xmldata(id int,data xml)
  insert into #xmldata
  select
  id = '011', 
  data =  '&lt;Root&gt;  
  &lt;ProductDescription ProductID="1" ProductName="Road Bike"&gt;  
  &lt;Features&gt;  
    &lt;Warranty&gt;1 year parts and labor&lt;/Warranty&gt;  
    &lt;Maintenance&gt;3 year parts and labor extended maintenance is available&lt;/Maintenance&gt;  
  &lt;/Features&gt;  
  &lt;/ProductDescription&gt;  
  &lt;/Root&gt;' 
  
  select * from #xmldata
  
  SET @ProdID =  #xmldata.data.value('(/Root)[1]', 'varchar' )  
  SELECT @ProdID  
  
  drop table #xmldata
  </code></pre>