title: Need to get attribute name-value pairs for root element only, in T-SQL query
body: <p>I've created a table-valued function which returns a list of attribute name-value pairs, when fed an XML fragment, based on Ben Davis's excellent response <a href="https://stackoverflow.com/questions/241407/get-the-names-of-attributes-from-an-element-in-a-sql-xml-column">here</a>. It works, but returns a list of all the attribute name-value pairs in the entire fragment, when I'd like to restrict it to just those on the root element. How can I do this? Thank you, from an XQuery newbie.</p>
  
  <pre><code>INSERT INTO @attributeList
  SELECT DISTINCT
      CAST(attribute.name.query('local-name(.)') AS VARCHAR(100)),
      attribute.name.value('.','NVARCHAR(MAX)')
  FROM @xml.nodes('//@*') attribute(name)
  </code></pre>
  
  <p>ETA: As it turns out after some experimentation, the selector 'node()/@*' works. Thanks to those who helped. </p>
  
  <p>I am using this in a simple data-migration application or data pump front-ending Sitecore. I've written a utility that can take POCO objects in .NET and get them into Sitecore, but now am constructed a migration and logging database. Source objects are stored in one place as XML. Thank you again.</p>