jamesagnew
2005-05-28 21:03:20 UTC
Hi
I'm trying to write a query that moves a node (and its children) from
one part of an xml tree to another.
Here's what I've got so far:
UPDATE tbl_tree SET theTree.modify('
insert (//node()[@id="7"])[1]
into (//node()[@id="1"])[1]
')
This successfully copies node 7 into node 1, but has also leaves the
original copy of node 7.
The problem I have is how to delete that original node whilst leaving
the newly inserted copy untouched?
I can't filter by id number, because that exists in two places, nor can
I rewrite the id number at the time of copying.
I thought about recording the parentID and position() of the original
node and then only delete the node that matches, but I've been unable
to get position() to return an value in SQL Server 2005.
Is there a simpler way to do this?
I've been hitting my head against this all day so I'd really appreciate
some guidance.
Many thanks, James
I'm trying to write a query that moves a node (and its children) from
one part of an xml tree to another.
Here's what I've got so far:
UPDATE tbl_tree SET theTree.modify('
insert (//node()[@id="7"])[1]
into (//node()[@id="1"])[1]
')
This successfully copies node 7 into node 1, but has also leaves the
original copy of node 7.
The problem I have is how to delete that original node whilst leaving
the newly inserted copy untouched?
I can't filter by id number, because that exists in two places, nor can
I rewrite the id number at the time of copying.
I thought about recording the parentID and position() of the original
node and then only delete the node that matches, but I've been unable
to get position() to return an value in SQL Server 2005.
Is there a simpler way to do this?
I've been hitting my head against this all day so I'd really appreciate
some guidance.
Many thanks, James