开发者

how to change a parent id of child and subchilds in hierarchyid

开发者 https://www.devze.com 2023-03-02 15:26 出处:网络
idhierid --------------------- 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百科/
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/');
0

精彩评论

暂无评论...
验证码 换一张
取 消