Is there a FOR XML variant that can add attributes with arbritrary values? I'm trying to create a query similar to this

SELECT
'foo' AS Detail,
'bar' AS Detail,
'baz' AS Detail
FOR XML PATH ('Header')


To produce something like this-

&lt;Header&gt;
  &lt;Detail type="A"&gt;foo&lt;/Detail&gt;
  &lt;Detail type="B"&gt;bar&lt;/Detail&gt;
  &lt;Detail type="C"&gt;baz&lt;/Detail&gt;
&lt;/Header&gt;


and it seems like there's no way to create attributes without assigning column values into them.
The query you have

SELECT
'foo' AS Detail,
'bar' AS Detail,
'baz' AS Detail
FOR XML PATH ('Header')


concatenates the values to a single Detail element.

&lt;Header&gt;
  &lt;Detail&gt;foobarbaz&lt;/Detail&gt;
&lt;/Header&gt;


To have multiple Detail elements you need to separate the columns with a null.

SELECT
'foo' AS Detail,
 null,
'bar' AS Detail,
 null,
'baz' AS Detail
FOR XML PATH ('Header')


&lt;Header&gt;
  &lt;Detail&gt;foo&lt;/Detail&gt;
  &lt;Detail&gt;bar&lt;/Detail&gt;
  &lt;Detail&gt;baz&lt;/Detail&gt;
&lt;/Header&gt;


And then you use the @ syntax suggested in the answer by Rob Farley to get the result you are looking for.

SELECT
'A' AS 'Detail/@type', 
'foo' AS Detail,
 null,
'B' AS 'Detail/@type', 
'bar' AS Detail,
 null,
'C' AS 'Detail/@type', 
'baz' AS Detail
FOR XML PATH ('Header')


&lt;Header&gt;
  &lt;Detail type="A"&gt;foo&lt;/Detail&gt;
  &lt;Detail type="B"&gt;bar&lt;/Detail&gt;
  &lt;Detail type="C"&gt;baz&lt;/Detail&gt;
&lt;/Header&gt;