如何进行 XQuery - tsql
我得到了这个 XML。
<ArrayOfGuid xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<guid>475B07C8-CDEA-4000-BAAE-485336190E10</guid>
<guid>6E5B87BC-CF80-4AB2-939E-ED951FA604AB</guid>
<guid>31BFDA60-3BB2-49DC-8C69-10F6E1B540CA</guid>
</ArrayOfGuid>
需要得到类似这样的结果:
BatchGUID
475B07C8-CDEA-4000-BAAE-485336190E10
6E5B87BC-CF80-4AB2-939E-ED951FA604AB
31BFDA60-3BB2-49DC-8C69-10F6E1B540CA
不知何故,我陷入了
DECLARE @BatchGUID XML
SET @BatchGUID = '<ArrayOfGuid xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<guid>475B07C8-CDEA-4000-BAAE-485336190E10</guid>
<guid>6E5B87BC-CF80-4AB2-939E-ED951FA604AB</guid>
<guid>31BFDA60-3BB2-49DC-8C69-10F6E1B540CA</guid>
</ArrayOfGuid>'
DECLARE @t_xml TABLE
(
BatchGUID XML
)
INSERT INTO @t_xml
SELECT @BatchGUID
SELECT C.* FROM @t_xml
cross apply (select name.value('guid[1]', 'uniqueidentifier') as [BatchGUID]
from BatchGUID.nodes('//ArrayOfGuid/guid') as c(name)) as C
This is returned me
BatchGUID
NULL
NULL
NULL
需要知道我在这里做错了什么。
谢谢,
I got this XML.
<ArrayOfGuid xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<guid>475B07C8-CDEA-4000-BAAE-485336190E10</guid>
<guid>6E5B87BC-CF80-4AB2-939E-ED951FA604AB</guid>
<guid>31BFDA60-3BB2-49DC-8C69-10F6E1B540CA</guid>
</ArrayOfGuid>
Need to get the results like
BatchGUID
475B07C8-CDEA-4000-BAAE-485336190E10
6E5B87BC-CF80-4AB2-939E-ED951FA604AB
31BFDA60-3BB2-49DC-8C69-10F6E1B540CA
Somehow I am stuck with
DECLARE @BatchGUID XML
SET @BatchGUID = '<ArrayOfGuid xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<guid>475B07C8-CDEA-4000-BAAE-485336190E10</guid>
<guid>6E5B87BC-CF80-4AB2-939E-ED951FA604AB</guid>
<guid>31BFDA60-3BB2-49DC-8C69-10F6E1B540CA</guid>
</ArrayOfGuid>'
DECLARE @t_xml TABLE
(
BatchGUID XML
)
INSERT INTO @t_xml
SELECT @BatchGUID
SELECT C.* FROM @t_xml
cross apply (select name.value('guid[1]', 'uniqueidentifier') as [BatchGUID]
from BatchGUID.nodes('//ArrayOfGuid/guid') as c(name)) as C
This is returning me
BatchGUID
NULL
NULL
NULL
Need to know what I'm doing wrong here.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你们是如此非常接近!
您的问题是您正在从
guid
节点中选择guid[1]
节点的值。当然,guid
节点不包含任何子节点 - 您希望从该节点本身选择值(表示为.
)You are so very close!
Your problem is that you're selecting the value of the
guid[1]
node from within theguid
node. Of course, theguid
node doesn't contain any children - you want to select the value from that node itself (which is expressed as.
)