【问题标题】:How to save results as xml in SQL Server Management Studio?如何在 SQL Server Management Studio 中将结果保存为 xml?
【发布时间】:2012-02-05 20:03:24
【问题描述】:

我正在尝试 TDD 并创建假对象,我想使用测试数据库中的 XML。因此,我想创建在 SQL Server Management Studio 中运行的查询结果的 XML。

但我无法在 SQL Server Management Studio 中找到如何以 XML 格式获取结果。这可能吗?怎么做?

【问题讨论】:

    标签: sql sql-server xml ssms


    【解决方案1】:

    您可以使用“FOR XML”将查询结果输出到 XML。

    例如:

    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
    

    【讨论】:

      猜你喜欢
      • 2012-05-27
      • 1970-01-01
      • 1970-01-01
      • 2013-11-29
      • 2010-12-03
      • 2019-01-16
      • 1970-01-01
      • 2013-11-17
      • 1970-01-01
      相关资源
      最近更新 更多