您好我是使用 XML 文件的新手,
我尝试将文件 ICD.xml 插入到 sql 表
XML 文件格式中,例如这样
<letter>
<title>#</title>
<mainTerm>
<title>1-propanol</title>
<cell col="2">T51.3X1</cell>
<cell col="3">T51.3X2</cell>
<cell col="4">T51.3X3</cell>
<cell col="5">T51.3X4</cell>
<cell col="6">--</cell>
<cell col="7">--</cell>
</mainTerm>
<mainTerm>
<title>2-propanol</title>
<cell col="2">T51.2X1</cell>
<cell col="3">T51.2X2</cell>
<cell col="4">T51.2X3</cell>
<cell col="5">T51.2X4</cell>
<cell col="6">--</cell>
<cell col="7">--</cell>
</mainTerm>
我用这个代码
Declare @xml XML
Select @xml = CONVERT(XML,bulkcolumn,2) FROM OPENROWSET(BULK 'File Path',SINGLE_BLOB) AS X
SET ARITHABORT ON
Insert into dbo.TestXML
(
C1,C3,C4,C5,C6,C7
)
Select
p.value('C1[1]','VARCHAR(100)') AS C1,
P.value('C2[1]','VARCHAR(100)') AS C2,
P.value('C3[1]','VARCHAR(100)') AS C3,
P.value('C4[1]','VARCHAR(100)') AS C4,
P.value('C5[1]','VARCHAR(100)') AS C5,
P.value('C6[1]','VARCHAR(100)') AS C6,
P.value('C7[1]','VARCHAR(100)') AS C7,
From @xml.nodes('/letter/title') PropertyFeed(P)
但我的语法有错误你能帮我吗,如果有另一种方法thnx