使用SQL Server 2008表中的新值更新Xml属性
发布时间:2020-05-24 09:03:53 所属栏目:MsSql 来源:互联网
导读:我在SQL Server 2008中有一个表,它有一些列.其中一列是Xml格式 我想更新一些属性. 例如,我的Xml列的名称是XmlText,它在5个第一行中的值如下: Identification Name=John Family=Brown Age=30 / Identification Name=Smith Family=Johnson Age=
|
我在SQL Server 2008中有一个表,它有一些列.其中一列是Xml格式
例如,我的Xml列的名称是XmlText,它在5个第一行中的值如下: <Identification Name="John" Family="Brown" Age="30" /> <Identification Name="Smith" Family="Johnson" Age="35" /> <Identification Name="Jessy" Family="Albert" Age="60" /> <Identification Name="Mike" Family="Brown" Age="23" /> <Identification Name="Sarah" Family="Johnson" Age="30" /> 我想更改30到40之间的所有Age属性,如下所示: <Identification Name="John" Family="Brown" Age="40" /> <Identification Name="Smith" Family="Johnson" Age="35" /> <Identification Name="Jessy" Family="Albert" Age="60" /> <Identification Name="Mike" Family="Brown" Age="23" /> <Identification Name="Sarah" Family="Johnson" Age="40" /> 解决方法从问题的早期版本看,您的XML实际上位于表中的不同行上.如果是这种情况,您可以使用它.update YourTable set
XMLText.modify('replace value of (/Identification/@Age)[1] with "40"')
where XMLText.value('(/Identification/@Age)[1]','int') = 30
使用表变量的工作示例. declare @T table(XMLText xml)
insert into @T values('<Identification Name="John" Family="Brown" Age="30" />')
insert into @T values('<Identification Name="Smith" Family="Johnson" Age="35" />')
insert into @T values('<Identification Name="Jessy" Family="Albert" Age="60" />')
insert into @T values('<Identification Name="Mike" Family="Brown" Age="23" />')
insert into @T values('<Identification Name="Sarah" Family="Johnson" Age="30" />')
update @T set
XMLText.modify('replace value of (/Identification/@Age)[1] with "40"')
where XMLText.value('(/Identification/@Age)[1]','int') = 30
select *
from @T (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- SQL Native Client 10性能不佳(由于服务器端游标)
- Redis中实现查找某个值的范围
- sql-server – 为什么这个查询不使用索引假脱机?
- sql – Oracle – ORA-01489:字符串连接的结果太长
- SqlServer提示“列前缀tempdb.无效: 未指定表名”问题解决方
- redis实现加锁的几种方法示例详解
- VB.NET调用MySQL存储过程并获得返回值的方法
- sql – 选择除一个字段外的所有字段?
- sql-server – 现有的DAO代码是否适用于SQL Server?
- sql-server – SQL Profiler(SQL Server 2000),如何仅过滤我
