Reputation: 4127
id hierid
---------------------
2 | /2/
7 | /2/7/
8 | /2/8/
11 | /2/7/11/
13 | /2/8/13/
17 | /2/8/17/
37 | /2/8/37/
i want to change the root of this to /3/ that means the output i want to get is
id hierid
---------------------
2 | /3/
7 | /3/7/
8 | /3/8/
11 | /3/7/11/
13 | /3/8/13/
17 | /3/8/17/
37 | /3/8/37/
like this how can i do it using hierarchyid
Upvotes: 3
Views: 1849
Reputation: 425833
UPDATE mytable
SET hierid = hierid.GetReparentedValue('/2/', '/3/')
WHERE hierid.IsDescendantOf('/2/') = 1
Upvotes: 4
Reputation: 7283
How about this:
UPDATE tbl SET hierid = REPLACE(hierid, '/2/', '/3/');
Upvotes: 2