I'm trying to find the quickest way to output XML results to disk from within SQL Server. This needs to be automated and quick as there are thousands of records to process.
These are the options that I am aware of:
- sp_OACreate & sp_OAMethod
- xp_cmdshell & osql.exe
- SSIS package
- Assembly DLL (SQLBulkCopy Class from .NET)
- BCP utility
Currently using the first option (sp_OACreate & sp_OAMethod) to create a new file for each result. In my environment, the client statistics show that it takes 374 milliseconds to execute and generate one file (with close to nothing in it).
I came across one article that compares using sp_OACreate & sp_OAMethod with other approaches and it is way slower. However, it does not compare performance for BCP, SSIS, DLL or other approaches. https://www.sqlservercentral.com/articles/writing-to-a-file-using-the-sp_oacreate-stored-procedure-and-osql-the
A list of benchmarks for each option would be useful but I can't seem to find that information online. My last option is to implement and test each option to see which is fastest but I'm hoping someone has some information.