更新时间:2022-10-16 19:35:18
还有一个选择 - 使用 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.
:XML ON
as a first line in your SQL file (let's call it input.sql)
sqlcmd -S <your-server> -i input.sql -o output.xml