从 SQL Server 2008 生成 XML 文件 [英] Generating XML file from SQL Server 2008
本文介绍了从 SQL Server 2008 生成 XML 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个应用程序,我需要将 SQL 响应作为 XML 获取到 XML 文件中(并将其存储在某个物理位置,例如 c:\xyz.xml).
我能够使用 SQL Server 中可用的规定生成 XML 内容,如下所示.
SELECT * FROM @Table FOR XML AUTO, ELEMENTS
其中:@Table
是表变量.
我想知道如何将查询输出从 SQL Server 本身存储到 XML 文件中.
解决方案
还有一个选择 - 使用 sqlcmd 工具.
- 添加
:XML ON
作为 SQL 文件的第一行(我们称之为 input.sql) - 像这样的命令可以解决问题:
<块引用>
sqlcmd -S <你的服务器>-i 输入.sql -o 输出.xml
I am working on an application where I need to get the SQL response as XML into an XML file (and to store it in some physical location, say c:\xyz.xml).
I am able to generate the XML content using the provisions available in SQL Server as shown below.
SELECT * FROM @Table FOR XML AUTO, ELEMENTS
where: @Table
is a table variable.
I want to know how I can store the query output to an XML file from SQL Server itself.
解决方案
There's one more option - use sqlcmd tool.
- Add
:XML ON
as a first line in your SQL file (let's call it input.sql) - A command like this will do the trick:
sqlcmd -S <your-server> -i input.sql -o output.xml
这篇关于从 SQL Server 2008 生成 XML 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文