Updating “Hierarchyid” in SQL Server

泄露秘密 提交于 2019-12-04 18:18:36

Use the "GetReparentedValue" Function to do it.

This is what I did for a table in my database :

DECLARE @FatherNode AS _INT_

SELECT @FatherNode = [PLC_PLC_ID]
FROM [dbo].[Place]
WHERE ([PLC_ID] = @PLC_ID)

UPDATE [dbo].[Place]
SET 
    [PLC_Tree] = [PLC_Tree].GetReparentedValue([dbo].[PLC_IDToTree](@FatherNode),[dbo].[PLC_IDToTree](@PLC_PLC_ID))
WHERE 
    ([PLC_Tree].IsDescendantOf([dbo].[PLC_IDToTree](@PLC_ID)) = 1) OR
    ([PLC_ID] = @PLC_ID)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!