Question

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

Was it helpful?

Solution

UPDATE  mytable
SET     hierid = hierid.GetReparentedValue('/2/', '/3/')
WHERE   hierid.IsDescendantOf('/2/') = 1

OTHER TIPS

How about this:

UPDATE tbl SET hierid = REPLACE(hierid, '/2/', '/3/');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top