SQL Server:多行XML

Vil*_*ric 2 xml sql sql-server ssis ssis-2012

我提取了xml文件并将其移至SQL Server。现在看起来像这样。

在此处输入图片说明

现在,我正在尝试将其转换为XML数据类型。

DECLARE @XML AS XML

SELECT @XML = convert(xml,[Column 0],2) FROM TestExtract
Run Code Online (Sandbox Code Playgroud)

但是我收到这个错误

XML解析:第1行,字符43,无法切换编码

也许我应该将所有行合并为一?然后转换呢?请告知任何选项。

谢谢!

Had*_*adi 5

I used SSIS, flat file as a source and ole db(SQL server) as destination

Why you haven't imported the XML using XML Source instead of Flat File source?

If the XML file is well structured then you can use an XML Source to import data into SQL Server, there are many example found online:

Other approach

You can directly read the XML file from SQL Server using ad hoc queries (OPENROWSET):

Current situation

First of all combine all rows into one value, then try to convert the value.

DECLARE @strXML VARCHAR(MAX)
DECLARE @XML AS XML
SET @strXML = ''

SELECT @strXML = @strXML + [Column 0] FROM Testextract
//SELECT @strXML = @strXML + [Column 0] + CHAR(13) + CHAR(10) FROM Testextract    

SET @XML = convert(xml,@strXML,2)
Run Code Online (Sandbox Code Playgroud)