我正在使用SQL Server 2014使用xquery查询XML文本。我可以插入部分XML文本进行查询,但我需要能够指向本地文件来读取和查询它,并且无法弄清楚如何执行此操作。以下是我目前正在做的事情。
declare @xmldata xml
set @xmldata = '
<Orders>
<Order OrderID="100" OrderDate="1/30/2012">
<OrderDetail ProductID="1" Quantity="3">
<Price>350</Price>
</OrderDetail>
<OrderDetail ProductID="2" Quantity="8">
<Price>500</Price>
</OrderDetail>
<OrderDetail ProductID="3" Quantity="10">
<Price>700</Price>
</OrderDetail>
</Order>
<Order OrderID="200" OrderDate="2/15/2012">
<OrderDetail ProductID="4" Quantity="5">
<Price>120</Price>
</OrderDetail>
</Order>
</Orders>'
SELECT x.c.value('(OrderDetail)[2]', 'varchar(100)') as OrderDetail
FROM @xmldata.nodes('/Orders/Order') x(c)
--XMl File Location: "C:\Users\User\X\Example.xml")
提前致谢!
答案 0 :(得分:0)
试试这个https://msdn.microsoft.com/en-CA/library/ms191184.aspx
INSERT INTO T(XmlCol)
SELECT * FROM OPENROWSET(
BULK 'c:\SampleFolder\SampleData3.txt',
SINGLE_BLOB) AS x;