title: Select nodes in T-SQL XML by name given in a variable
body: <p>I'm trying to select nodes in XML document by provided name.</p>
  
  <pre class="lang-sql prettyprint-override"><code>declare @xdoc xml = '
  
      &lt;data&gt;
          &lt;box&gt;&lt;id&gt;1&lt;/id&gt;&lt;weight&gt;10&lt;/weight&gt;&lt;/box&gt;
          &lt;tube&gt;&lt;id&gt;2&lt;/id&gt;&lt;weight&gt;20&lt;/weight&gt;&lt;/tube&gt; &lt;!-- Should be skipped --&gt;
          &lt;box&gt;&lt;id&gt;3&lt;/id&gt;&lt;weight&gt;30&lt;/weight&gt;&lt;/box&gt;
      &lt;/data&gt;
  
  '
  
  declare @node nvarchar(100)='box'
  
  select
      ref.value('id[1]','bigint') as Id,
      ref.value('weight[1]','bigint') as Weight
  from @xdoc.nodes('/data/*[local-name()=[sql:variable("@node")]]') as xdata(ref)
  -- WORKS FINE:from @xdoc.nodes('/data/*[local-name()="box"]') as xdata(ref)
  </code></pre>
  
  <p>and it gives me error message:</p>
  
  <pre><code>XQuery [nodes()]: Syntax error near '[', expected a step expression.
  </code></pre>
  
  <p>How do I access local variable in xml.nodes()? Or may be there is some better way to achieve it?</p>