我必须生成格式为“ =“ UTF-8”的xml文件。我使用了bcp queryout。正在生成xml文件。但是我的问题是xml文件验证失败。有人可以帮助我解决这个问题吗?这是我的代码。
DECLARE @xmlBody AS VARCHAR(MAX)= '<?xml version="1.0" encoding="UTF-8"?>'+ CAST(@xmlStr AS VARCHAR(MAX)) INSERT INTO [dbo].[MasterXml] ([PurchaseOrderID] ,[Code]) values (@PurchaseOrderID, @xmlBody) Declare @command varchar(8000) SET @command= 'bcp "SELECT TOP 1 [Code] from [tec_Dev].[dbo].[MasterXml] where PurchaseOrderID='+ CAST( @PurchaseOrderID As varchar(20))+'" queryout ' +@uploadFolder + CAST(@PurchaseOrderID AS varchar(20))+'.xml' +' -T -N -w -c -C65001' print @command EXEC xp_cmdshell @command
我找到了解决方案
+@uploadFolder + CAST(@PurchaseOrderID AS varchar(20))+'.xml' +' -T -N -w -c -C65001'
我从代码中删除了-w。然后就可以了。但是它仅适用于Microsoft SQL Server 2014(SP2-CU6)(KB4019094)-12.0.5553.0(X64)。
https://support.microsoft.com/en-us/help/3136780/utf-8-encoding-support-for- the-bcp-utility-and-bulk-insert-transact-sq