且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更新 SQL Server 中的 XML 节点值

更新时间:2021-11-14 06:37:18

你可以这样做:

UPDATE 
   dbo.profiles
SET 
   ProfileXML.modify('replace value of (/ProblemProfile/GroupID/text())[1] with "0"')
WHERE
   id = 23

SQL Server 2005 XQuery 和 XML-DML 详细了解您可以使用 .modify 关键字做什么(插入、删除、替换等).).

Check out this article on SQL Server 2005 XQuery and XML-DML for more details on what you can do with the .modify keyword (insert, delete, replace etc.).

马克

PS:为了获得价值,这样做会容易得多:

PS: In order to get the value, it would be a lot easier to do just this:

SELECT ProfileXML.value('(/ProblemProfile/GroupID)[1]', 'int') as ID
FROM dbo.profiles
WHERE id = 23

(当然除非您需要将 XML 作为 SQL 变量用于稍后的其他操作)

(unless of course you need the XML as a SQL variable for something else later on)