我已经编写了一个CLR程序集,可以将表格数据导出到XML文件中。现在我想将这些数据导入到另一个实例的临时表中。 XML文件的结构如下:
<row>
<SystemInformationID>1</SystemInformationID>
<Database_x0020_Version>10.00.80404.00</Database_x0020_Version>
<VersionDate>2008-04-04T00:00:00</VersionDate>
<ModifiedDate>2008-04-04T00:00:00</ModifiedDate>
</row>
我希望在目标位置解析XML并将其导入临时表中。 我已经在那里有了主表,所以我可以从那里获取表结构。
有没有办法? 我使用OPENXML,但似乎无法正常工作。 我可以将XML文件读取到表中,该表将存储在具有XML数据类型的列中。 我的问题是解析该列中的数据。
这是一次尝试:
CREATE TABLE ##T (IntCol int, XmlCol xml)
GO
INSERT INTO ##T(XmlCol)
SELECT * FROM OPENROWSET(
BULK 'c:\HISOutput.xml',
SINGLE_CLOB) AS x
--works correctly up to this point
DECLARE @x xml
DECLARE @id int
SELECT @x=XmlCol FROM ##T
EXEC sp_xml_preparedocument @id OUTPUT, @x
SELECT *
FROM OPENXML (@id,'/row',2)
WITH
dbo.awbuildversion
--I used dbo.awbuildversion table from AdventureWorks DB for testing
this doesn't show the first column no matter how I change the OPENXML instruction.
提前感谢你。