title: how to output xml with attribute and field value in TSQL
body: <p>I'd like to output some fields from a table in xml. I need to put the name of the column in the name-attribute. The output must resemble:</p>
  
  <pre><code>&lt;udfields&gt;
  &lt;udfield name="infoplanner"&gt;Test for the info&lt;/udfield&gt;
  &lt;udfield name="plant"&gt;Amsterdam&lt;/udfield&gt;
  &lt;udfield name="capability"/&gt;
  &lt;/udfields&gt;
  </code></pre>
  
  <p>I tried things like:</p>
  
  <pre><code>SELECT TOP 3
      ko.infoPlanner AS "udfield/name/@infoplanner"
    , ko.plant AS "udfield/name/@plant"
    , ko.capability AS "udfield/name/@capability"
  FROM    sometable ko
  WHERE   CONVERT(VARCHAR(8), ko.datumtijd, 112) = CONVERT(VARCHAR(8), GETDATE(), 112)
          AND COALESCE(ko.infoPlanner, '') &lt;&gt; ''
  FOR     XML PATH('')
  </code></pre>
  
  <p>thanks in advance, leon</p>