I have a table with a XMLTYPE column named 'InvoiceXML'.
The data in this column is XML in the form:
<Invoice CustomerNum="1234" >
<CustomDeliveryDetails />
</Invoice>
When I do a
SELECT ... FOR XML PATH(''), ROOT('Invoices')
I end up with:
<Invoices>
<InvoiceXML>
<Invoice CustomerNum="1234" >
<CustomDeliveryDetails />
</Invoice>
</InvoiceXML>
</Invoices>
How do I stop the column name InvoiceXML appearing in the output?
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')
Edit 1 The subquery (select T.invoiceXML
) has no column name so it is removed.
Try:
SELECT cast(cast(InvoiceXML as nvarchar(max)) + '' as XML)
FROM whatever
FOR XML PATH(''), ROOT('Invoices')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With