title: Insert into xml in sql using modify method
body: <p>I have to modify the existing xml in a table field value.
  Each row value has different xml tags  like </p>
  
  <p>1 row.
  <code>'&lt;root&gt;&lt;comments&gt;&lt;comment&gt;comments1&lt;/comment&gt;&lt;comment&gt;comments2&lt;/comment&gt;&lt;/comments&gt;&lt;/root&gt;'</code></p>
  
  <p>2 row . </p>
  
  <pre><code>'&lt;Users&gt;&lt;User&gt;&lt;Name&gt;MAK&lt;/Name&gt;&lt;/User&gt;&lt;User&gt;&lt;Name&gt;DANNY&lt;/User&gt;&lt;/Users&gt;'
  </code></pre>
  
  <p>I need to add a tag <code>&lt;Resource&gt;some ID&lt;/Resource&gt;</code> 
  after the root node.</p>
  
  <p>like <code>'&lt;Users&gt;**&lt;Resource&gt;some ID&lt;/Resource&gt;**&lt;User&gt;&lt;Name&gt;comments1&lt;/Name&gt;&lt;/User&gt;&lt;User&gt;&lt;Name&gt;comments2&lt;/User&gt;&lt;/Users&gt;'</code></p>
  
  <p>I have tried with the below code .</p>
  
  <pre><code>declare @xml xml
  set @xml = '&lt;root&gt;&lt;comments&gt;&lt;comment&gt;comments1&lt;/comment&gt;&lt;comment&gt;comments2&lt;/comment&gt;&lt;/comments&gt;&lt;/root&gt;'
  declare @Note varchar(10)
  declare @insertnode nvarchar(100)
  set @insertnode='commeressd'
  declare @mainnode varchar(50)
  set @mainnode='(//root)[1]'
  set @Note = 'comment3'
  SET @xml.modify('insert &lt;Resource&gt;{xs:string(sql:variable("@insertnode"))}&lt;/Resource&gt; as first into {xs:string(sql:variable("@mainnode"))}')
  select @xml
  </code></pre>
  
  <p>the expression after </p>
  
  <blockquote>
    <p>into</p>
  </blockquote>
  
  <p>is giving the error</p>
  
  <blockquote>
    <p>XQuery [modify()]: Syntax error near '{'</p>
  </blockquote>
  
  <p>..how do we specify this into expression also dynamically.</p>
  
  <p>Any help would be appreciated.</p>