Generating XML file from SQL Server 2008
sql, sql-server, sql-server-2008, xml
Solution
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
Problem
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.