我需要将GroupID字段更新为0.我已经找到了如何检索值,我现在遇到更新它的问题.
任何帮助都会很棒!
<ProblemProfile>
<GroupID>-1</GroupID>
<LayoutID>1</LayoutID>
<MyQueries>false</MyQueries>
</ProblemProfile>
Declare @Result xml
set @Result = convert(xml,(select ProfileXML from profiles where id = 23))
SELECT x.value('.', 'int') ID
FROM @Result.nodes('/ProblemProfile/GroupID') as R(x)
Run Code Online (Sandbox Code Playgroud)
更新
我现在需要做的是更新每一行具有'foo'值的GroupID
declare @foo int
set @foo = -1
UPDATE profiles
SET ProfileXML.modify('replace value of (/ProblemProfile/GroupID/text())[1] with "0"')
WHERE ProfileXML.value('(/ProblemProfile/GroupID)[1]', 'int') = @foo
Run Code Online (Sandbox Code Playgroud)
这仅更新符合此条件的第一行.我如何更新每一行?
更新2 该声明有效.原来第一个节点的数据库结构可以不同.每行更新一个简单的//GroupID...etc.哈哈,总是让我们蠢蠢的小东西.