XML : Convert SQL row into XML tag with value and attibutes

I have a simple flat SQL table with three columns A, B and C:

  CREATE TABLE [tmp]  (    [A] NVARCHAR(32) NULL  , [B] NVARCHAR(32) NULL  , [C] NVARCHAR(32) NULL  );    

I would like to convert each row to an XML object like

  <Parameter name="A" description="B">666</Parameter>    

If I use FOR XML AUTO, all columns are converted to an XML attribute. I can use FOR XML AUTO, ELEMENTS or use FOR XML RAW to get tags instead, but I would like to convert columns A and B to an attribute and use column C as the tag value.

How can I get this result?

No comments:

Post a Comment