我有一个名为“invoicexml”的xmltype列的表。
此列中的数据是XML格式的:

<Invoice CustomerNum="1234" >
<CustomDeliveryDetails />
</Invoice>

当我做
SELECT ... FOR XML PATH(''), ROOT('Invoices')

我的结局是:
<Invoices>
 <InvoiceXML>
  <Invoice CustomerNum="1234" >
  <CustomDeliveryDetails />
  </Invoice>
 </InvoiceXML>
</Invoices>

如何停止输出中出现的列名invoicexml?

最佳答案

declare @T table (invoiceXML xml)

insert into @T values (
  '<Invoice CustomerNum="1234" >
     <CustomDeliveryDetails />
   </Invoice>
  ')

insert into @T values (
  '<Invoice CustomerNum="4321" >
     <CustomDeliveryDetails />
   </Invoice>
  ')

select (select T.invoiceXML)
from @T as T
for xml path(''), root('Invoices')

编辑1子查询(select T.invoiceXML)没有列名,因此将其删除。

07-24 20:14