I am trying out TDD and creating fake objects, I want to use XML from the test DB. Thus I want to create XML of the results of a query, which I am running in SQL Server Management Studio.
我正在尝试TDD并创建假对象,我想使用测试数据库中的XML。因此,我想创建一个查询结果的XML,我在SQL Server Management Studio中运行。
But I am unable to find how to get the results as XML in SQL Server Management Studio. Is this possible? And How?
但我无法找到如何在SQL Server Management Studio中将结果作为XML获取。这可能吗?如何?
1 个解决方案
#1
13
You can use "FOR XML
" to output the results of a query to XML.
您可以使用“FOR XML”将查询结果输出到XML。
For example:
例如:
SELECT
o.Order_Number AS 'OrderNumber', --Element
o.Order_Total AS '@OrderTotal' --Attribute
FROM dbo.ORDER o
FOR XML PATH('ORDER'), ROOT('ORDERS') --Path / Root let you formulate the xml the way you want
#1
13
You can use "FOR XML
" to output the results of a query to XML.
您可以使用“FOR XML”将查询结果输出到XML。
For example:
例如:
SELECT
o.Order_Number AS 'OrderNumber', --Element
o.Order_Total AS '@OrderTotal' --Attribute
FROM dbo.ORDER o
FOR XML PATH('ORDER'), ROOT('ORDERS') --Path / Root let you formulate the xml the way you want