如何对SQL Server中的XML数据进行insert、update、delete .(二)

2014-11-24 10:23:31 · 作者: · 浏览: 1
CT @XMLVar.query('/catalog[1]');
结果集为:
1:
2:
3:
4: 49.99
5:

6:
7: Windows Cluster Server
8: Stephen Forte
9: 59.99
10:

11:



3.XML.Modify(replace)语句介绍

--替换属性
set @XMLVar.modify('replace value of(/catalog[1]/book[1]/@category))
with ("替换属性")'
--替换内容
set @XMLVar.modify('replace value of(/catalog[1]/book[1]/author[1]/text()[1]))
with("替换内容")'
--条件替换
set @XMLVar.modify('replace value of (/catalog[1]/book[2]/@category))
with(
if(count(/catalog[1]/book)>4) then
"条件替换1"
else
"条件替换2")'

SELECT @XMLVar.query('/catalog[1]');
结果集为:
1:
2:
3: Windows Step By Step
4: 替换内容
5: 49.99
6:

7:
8: Developing ADO .NET
9: Andrew Brust
10: 39.93
11:

12:
13: Windows Cluster Server
14: Stephen Forte
15: 59.99
16:

17:

作者“cnming”