This article transferred from: Https://stackoverflow.com/questions/44754356/sql-create-xml-how-to-set-unicode-utf-8
I found a solution via another. (Don ' t remember which website I found it) See code below. This code would export my file in Utf-8-bom encoding.
DECLARE @OLE INT EXECUTE sp_oacreate ' ADODB. Stream ', @OLE outputdeclare @Text xmlset @Text = n ' This is the test test string '; --(SELECT TOP (1) [XML] From Vw_warp_leveranciers_xml) DECLARE @Converted NVARCHAR (max) SET @Converted = CONVERT (NVARCHAR (max), @Text) EXECUTE sp_OA SetProperty @OLE, ' Type ', 2--1 = binary, 2 = Textexecute Sp_oasetpro Perty @OLE, ' Mode ', 3--0 = Not set, 1 read, 2 write, 3 Read/writeexe CUTE sp_OASetProperty @OLE, ' Charset ', ' UTF-8 '--' iso-8859-1 ' EXECUTE sp_oasetp Roperty @OLE, ' lineseparator ', ' Adlf ' Execute sp_OAMethod @OLE, ' Open ' execute sp_OA Method @OLE, ' writetext ', NULL, @Converted--text method--commit data and close text Streamexecute sp_OAMethod @OLE, ' SaveToFile ', NULL, ' d:\1.TXT ', 2--1 = notexist 2 = Overwriteexecute sp_OAMethod @OLE, ' Close ' EXECUTE sp_OADestroy @OLEEXECUTE sp_OADestroy @OLE
Go Sql-create xml-how to set Unicode UTF-8