关于SQLSERVER2012 XML空节点更新数据的问题

belsai 2021-01-07 12:49:37

DECLARE @t table(i int,x xml)
insert @t select 1,(select '0' as t1,'' as t2 for xml path)
select * from @t
update @t set x.modify('replace value of (/row/t1[1]/text())[1] with "new"')
update @t set x.modify('replace value of (/row/t2[1]/text())[1] with "new1"')
select * from @t

通过以上语句发现,当XML节点数据为空时,modify的replace value of无效,有什么办法解决?
...全文
168 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
belsai 2021-01-22
  • 打赏
  • 举报
回复
沉了,顶一下
belsai 2021-01-07
  • 打赏
  • 举报
回复

update @t set x.modify('delete /row/t2[1]')
update @t set x.modify('insert <t2>new</t2> after (/row/t1)[1]')
先删除再插入可以解决,但直接replace value of为什么不行呢?是SQLSERVER的BUG吗?

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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