March 26, 2013 at 1:10 am
Hi,
We are using Sql server 2008 R2 express. We are trying to use HierarchyID datatype to represent organizational structure. We have to insert a child by using parent id. I found this query
declare @root hierarchyid,@last_id hierarchyid,@id hierarchyid
select @root=orgnode from [adventureworks].HumanResources.EmployeeDemo where employeeid=1
SELECT @last_id = MAX(orgnode) FROM [adventureworks].HumanResources.EmployeeDemo WHERE orgnode.GetAncestor(1) = @root
SELECT @id=@root.GetDescendant(@last_id, NULL)
INSERT into [adventureworks].HumanResources.EmployeeDemo values(@id,12,'seh','Application Developer',1905-02-12);
But this inserts a node at end in particular level and i sometimes want to insert node in between other nodes in that level.How can i achieve that?
Viewing 0 posts
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy