xquery XML迭代读取值

lvxiaowei1983 2010-02-01 03:28:15
不好意思,不知道这个问题发帖在这里是否合适。

Declare @x xml

set @x='
<smss date="676876876876">

<address data="+6547689879088">
<sms date="5435435435435" read="1" status="-1" type="1" body="fdsfdsfsdfsf"/>
<sms date="65876876876876" read="1" status="-1" type="2" body="54654tgfffhfhfg"/>
</address>

<address data="+534654765876876">
<sms date="879868698" read="1" status="-1" type="1" body="8678768979878798gfdg"/>
<sms date="54765787687" read="1" status="-1" type="1" body="76876978098p009o"/>
<sms date="6y5765875" read="1" status="-1" type="1" body="76576587698798"/>
</address>

<address data="+76587687980">
<sms date="676787687" read="1" status="-1" type="1" body="hgfdhdghgdhg"/>
<sms date="5try" read="1" status="-1" type="1" body="gfdhggdhgd"/>
<sms date="y65y65" read="1" status="-1" type="1" body="reetrytr"/>
<sms date="y65y65" read="1" status="-1" type="1" body="ytrytrytrytr"/>
<sms date="y65y65" read="1" status="-1" type="1" body="ytrytrytry"/>
<sms date="y65y65" read="1" status="-1" type="1" body="uyiyjuyiu"/>
<sms date="y65y65" read="1" status="-1" type="1" body="oyoiukiu"/>
<sms date="y65y65" read="1" status="-1" type="1" body="ikyiy"/>
<sms date="y65y65" read="1" status="-1" type="1" body="kyiuykuykuy"/>
<sms date="y65y65" read="1" status="-1" type="1" body="kiykikuui"/>
</address>

</smss>


我想通过xquery 迭代 语句for 取出 “/smss/address/sms/@body”中所有@body的值,不知道select 语句怎么写。
...全文
93 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lvxiaowei1983 2010-02-01
  • 打赏
  • 举报
回复
............这边高手真的好多~~10分钟不到就完成了~~我惭愧啊~~给分。不知道分够不够给。
--小F-- 2010-02-01
  • 打赏
  • 举报
回复
是的 只有几个高手对这个熟悉

有请P梁 剪剪 和尚 FC
lvxiaowei1983 2010-02-01
  • 打赏
  • 举报
回复
这个问题我想了很久还没想出来。好像这里用SQL XML的人比较少的。
bancxc 2010-02-01
  • 打赏
  • 举报
回复

select a.b.value('@body','varchar(100)') as r
from @x.nodes('//sms[@body]') as a(b)
/*r
----------------------------------------------------------------------------------------------------
fdsfdsfsdfsf
54654tgfffhfhfg
8678768979878798gfdg
76876978098p009o
76576587698798
hgfdhdghgdhg
gfdhggdhgd
reetrytr
ytrytrytrytr
ytrytrytry
uyiyjuyiu
oyoiukiu
ikyiy
kyiuykuykuy
kiykikuui

(15 行受影响)
*/
???

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧