SQL 服务器:FOR XML 设置根属性

SQL Server : FOR XML set root attribute

如何将根属性设置为 SQL 服务器中 FOR XML 的列?

例如,如果您有 3 列,例如 'First Name'、'Last Name' 和 'Person',并且您希望输出类似于

<root type="person">
    <first Name/>
    <last name/>
</root>

尝试以下操作:

select 
    'person' as '@type'
    /*
    rest of stuff goes here...
    */
From someTable
FOR xml path('root')