How do I update a XML string in an ntext column in SQL Server?(如何更新 SQL Server 中 ntext 列中的 XML 字符串?)
本文介绍了如何更新 SQL Server 中 ntext 列中的 XML 字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个包含 2 列的 SQL 表.ID(int) 和值(ntext)
have a SQL table with 2 columns. ID(int) and Value(ntext)
值行中包含各种 xml 字符串.
The value rows have all sorts of xml strings in them.
ID Value
-- ------------------
1 <ROOT><Type current="TypeA"/></ROOT>
2 <XML><Name current="MyName"/><XML>
3 <TYPE><Colour current="Yellow"/><TYPE>
4 <TYPE><Colour current="Yellow" Size="Large"/><TYPE>
5 <TYPE><Colour current="Blue" Size="Large"/><TYPE>
6 <XML><Name current="Yellow"/><XML>
我该怎么做:
A.列出
`<TYPE><Colour current="Yellow",`
bearing in mind that there is an entry
<XML><Name current="Yellow"/><XML>
B.修改包含
<TYPE><Colour current="Yellow" to be
<TYPE><Colour current="Purple"
谢谢!4 你的帮助
推荐答案
在SQL Server 2005+
中,使用中间临时表:
In SQL Server 2005+
, using a intermediary temporary table:
DECLARE @q AS TABLE (xid INT NOT NULL, xdoc XML NOT NULL, modified TINYINT NOT NULL DEFAULT 0)
INSERT
INTO @q (xid, xdoc)
SELECT id, doc
FROM mytable
UPDATE @q
SET xdoc.modify('replace value of (/TYPE/@Colour)[1] with "blue"'),
modified = 1
WHERE xdoc.value('(/TYPE/@Colour)[1]', 'NVARCHAR(MAX)') = 'Yellow'
UPDATE mytable
SET doc = CAST(xdoc AS NVARCHAR(MAX))
FROM @q q
WHERE id = q.xid
AND q.modified = 1
这篇关于如何更新 SQL Server 中 ntext 列中的 XML 字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:如何更新 SQL Server 中 ntext 列中的 XML 字符串?


基础教程推荐
猜你喜欢
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 在多列上分布任意行 2021-01-01