how to change a parent id of child and subchilds in hierarchyid
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开发者_JS百科/
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
UPDATE mytable
SET hierid = hierid.GetReparentedValue('/2/', '/3/')
WHERE hierid.IsDescendantOf('/2/') = 1
How about this:
UPDATE tbl SET hierid = REPLACE(hierid, '/2/', '/3/');
精彩评论