SQL 中的 Xquery:选择子集
给定以下 xml 变量:
declare @x xml
select @x = '<Details>
<Description>
<Attributes>
<Name>A</Name>
<Values><RecordId>1</RecordId><RecordId>2</RecordId></Values>
</Attributes>
<Attributes>
<Name>B</Name>
<Values><RecordId>3</RecordId><RecordId>4</RecordId></Values>
</Attributes>
</Description>
</Details>'
我试图获取所有 Name 值及其所有 RecordId。我想在一份声明中做到这一点。我现在有以下内容。
create table #xml (element varchar(60))
insert into #xml
select RoleDetails.item.value('(Name)[1]', 'varchar(60)')
from
@x.nodes('/Details/Description/Attributes') AS RoleDetails(item)
我正在寻找的格式是:
A 1
2
B 3
4
Given the following xml variable:
declare @x xml
select @x = '<Details>
<Description>
<Attributes>
<Name>A</Name>
<Values><RecordId>1</RecordId><RecordId>2</RecordId></Values>
</Attributes>
<Attributes>
<Name>B</Name>
<Values><RecordId>3</RecordId><RecordId>4</RecordId></Values>
</Attributes>
</Description>
</Details>'
I am trying to get all Name values with all their RecordIds. I would like to do it in one statement. I have the following now.
create table #xml (element varchar(60))
insert into #xml
select RoleDetails.item.value('(Name)[1]', 'varchar(60)')
from
@x.nodes('/Details/Description/Attributes') AS RoleDetails(item)
The format I'm looking for would be:
A 1
2
B 3
4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以 XML 格式保存子集并允许代码执行 XML 操作变得更加容易。
It became easier to save the subset in the XML format and allow for code to do XML manipulation.