Microsoft SQL Server 2014更改生成的xml的格式

Microsoft SQL Server 2014更改生成的xml的格式,sql,sql-server,xml,tsql,Sql,Sql Server,Xml,Tsql,我正在SQL Server中使用FOR XML功能,但我想更改生成的XML的格式 这是我的疑问: SELECT * FROM dbo.myTable AS row FOR XML RAW, ELEMENTS, ROOT('rows') 结果是: <rows> <row> <name>A Time to Kill</name> <author>John Grisham</author>

我正在SQL Server中使用
FOR XML
功能,但我想更改生成的XML的格式

这是我的疑问:

SELECT * 
FROM dbo.myTable AS row 
FOR XML RAW, ELEMENTS, ROOT('rows')
结果是:

<rows>
    <row>
       <name>A Time to Kill</name>
       <author>John Grisham</author>
       <price>12.99</price>
    </row>
    <row>
       <name>Blood and Smoke</name>
       <author>Stephen King</author>
       <price>10</price>
    </row>
</rows>

消磨时间
约翰·格里森姆
12.99
血与烟
斯蒂芬金
10
但我想要的结果是:

<rows> 
    <row id="1"> 
        <cell>A Time to Kill</cell> 
        <cell>John Grisham</cell> 
        <cell>12.99</cell> 
    </row>
    <row id="2"> 
        <cell>Blood and Smoke</cell> 
        <cell>Stephen King</cell> 
        <cell>10</cell> 
    </row>
</rows>

消磨时间
约翰·格里沙姆
12.99
血与烟
斯蒂芬金
10
我怎样才能做到这一点?我尝试将“自动”更改为“原始”或“路径”,但没有成功

你好,拉法

Declare @YourTable table (id int,name varchar(50),author varchar(50),price money)
Insert Into @YourTable values 
 (1,'A Time to Kill','John Grisham',12.99)
,(2,'Blood and Smoke','Stephen King',10)

Select [@id]  = id
      ,[cell] = name
      ,null
      ,[cell] = author
      ,null
      ,[cell] = price
 From  @YourTable
 For   XML Path('row'),root('rows')
返回

<rows>
  <row id="1">
    <cell>A Time to Kill</cell>
    <cell>John Grisham</cell>
    <cell>12.9900</cell>
  </row>
  <row id="2">
    <cell>Blood and Smoke</cell>
    <cell>Stephen King</cell>
    <cell>10.0000</cell>
  </row>
</rows>

消磨时间
约翰·格里森姆
12.9900
血与烟
斯蒂芬金
10

Hi,祝贺SQL Server金牌:-)我知道,这里没有阳台:-)@Shnugo谢谢。不用担心,我会为这样的场合举办一个供应派对,制造噪音。。。“当你想到这件事时,有点难过。”拉斐尔森很高兴这件事起了作用