我需要從SQL Server返回XML中包含空格的列別名。 XML需要是這樣的:SQL Server:將列名稱指定爲屬性,並將節點值指定爲XML
<Records>
<Record>
<Field FieldName="PURCHASE_DETAIL_ID">31320</Field>
<Field FieldName="ORDER_ID">6507</Field>
<Field FieldName="PRODUCT_ORDER">1</Field>
</Record>
</Records>
我的表如下所示:
PURCHASE_DETAIL_ID | ORDER_ID | PRODUCT_ORDER
----------------------------------------------------
31320 6507 1
我想使用XML提取FOR XML
方法。
我嘗試了以下,它適用於單列,但不適用於多個。
SELECT
'PURCHASE_DETAIL_ID' AS [Field/@FieldName],
'GOLI' + RTRIM(CONVERT(VARCHAR(10), ol.ID)) AS [Field],
'ORDER_ID' AS [Field/@FieldName],
o.ID AS [Field],
'PRODUCT_ID' AS [Field/@FieldName],
P.ID AS [Field]
FROM ...
WHERE ...
FOR XML PATH('Record'), ROOT('Records')
」是你在這裏的新東西...... –