How to export from SQL Server to XML

回眸只為那壹抹淺笑 提交于 2019-12-05 02:39:46

问题


What is the easiest way to export to XML from SQL Server [Table or view] to XML?

This is what I have done till now

Execute Sql Task

SELECT * FROM Production.Product 
FOR XML AUTO, TYPE, ROOT('Data')

ResultSet XML

in left result set section I have created new variable 0 User::XMLVal

Script Task

 Dim sw As New IO.StreamWriter("D:\Apps\SSIS\test.xml")
    sw.Write(Dts.Variables("User::XMLVal").Value.ToString())


    sw.Dispose()

回答1:


If you want to use the task components, set up an Execute SQL Task to read the result of a SQL statement or stored procedure into a user-defined SSIS variable. Your statement above is a good example of what it should look like:

Then use the XML Task to write the contents of the variable to a file:




回答2:


You can also use the query in a data flow source adapter and use the Export Column Transformation --- Using SSIS to extract a XML representation of table data to a file

This saves you the trouble of managing your own scripts and what not, it's all out of the box functionality.



来源:https://stackoverflow.com/questions/9233703/how-to-export-from-sql-server-to-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!