I need to return a column alias that has spaces in it in XML from SQL Server. Since you can't have spaces in XML column names I'd like to return this alias in a "columnName" attribute. Generally, the XML would need to look like this:
<customers>
<customer name="Shmo, Joe">
<over50 columnName="Number of Orders Over 50 Pounds" value="10">
<cancelled columnName="Orders Cancelled" value="2">
</customer>
</customers>
The table looks as follows:
|Name |over50|cancelled
---------------------------
|Shmo, Joe| 10 | 2
If possible, I'd really like to use the "FOR XML" method of XML extraction. Thanks in advance for any insight.
1条答案
按热度按时间9gm1akwq1#
This should do it.
SQL Fiddle