2

我将数据从 SQL Server 导出到 XML 文件,如下所示:

USE Northwind;

SELECT * FROM Products FOR XML PATH;

对于NULL价值,它返回xsi:nil="true"

例如:<ProductName xsi:nil="true"/>

我可以在没有 的情况下导出xsi:nil="true"吗?

但我确实想要标签名称,例如:<ProductName /><ProductName></ProductName>

有人可以告诉我如何像这样导出吗?

谢谢。

4

1 回答 1

4

你可以试试这样的...

SELECT * FROM Products
    FOR XML RAW('customer'), ROOT('customers') 

for XML 语句中的 ROOT 子句为您的 XML 文档创建根元素以创建格式良好的 XML 文档,如果您想要 Elements 中的所有值,您可以在 FOR XML 语句中添加 Elements 子句,如下所示。

SELECT * FROM Products
FOR XML RAW('customer'), ROOT('customers'), Elements

现在,如果您仅在其末尾添加 XSINIL 子句,那么 ELEMENTS 将 null 值作为 ,否则它根本不会返回该元素。这将是这样的..

SELECT * FROM Products
FOR XML RAW('customer'), ROOT('customers'), Elements XSINIL 
于 2013-10-13T15:36:24.150 回答