简体   繁体   中英

Saving XML output from SQL Server to file as UTF-8

I'm using FOR XML PATH to create an XML inside SQL Server 2014 and I would like to save it as an UTF-8 file.

Is it possible to do this without using an external tool to convert the file?

Seems like this was fixed in SQL Server 2014 SP2 and can be done using the BCP tool:

https://support.microsoft.com/en-us/help/3136780/utf-8-encoding-support-for-the-bcp-utility-and-bulk-insert-transact-sq

To export UTF-8 data to SQL Server, use the BCP utility and run the following command:

bcp "query" out "drive:path\file_name" -c -C 65001

Using EXECUTE xp_cmdshell around this would probably fix the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM