Search code examples
sql-serverexcelms-officesqlxml

Return XML document from SQL Server 2008


I have a template of an Excel XML document. Is there anyway I can build the XML document is SQL and have SQL Server return the XML document to me via stored proc.?

I am trying to see if SQL Server can not just return the data for the spreadsheet but the actual Excel XML document with the data in it.

Something similar to this.

http://msdn.microsoft.com/en-us/library/office/aa191724%28v=office.11%29.aspx

I want to build the XML is SQL.


Solution

  • Yes, you can use the FOR XML clause.

    select * from table for xml raw
    

    You can also use XML AUTO or XML EXPLICIT