RationalGeek
RationalGeek

Reputation: 9599

SQL Server hierarchyid - insert new node between two existing sibling nodes

Let's say I have a hierarchyid column in SQL Server (2008 R2). Let's say I have the following nodes already in the table:

/1/
/1/1/
/1/2/

I'd like to create an insert statement that inserts between '/1/1/' and '/1/2/', creating node '/1/1.1/'. However, I don't want to hardcode '/1/1.1/'. I want to base the insert statement on knowing '/1/1/' and '/1/2/'. This will be a stored proc so it is okay if some T-SQL is necessary before the insert statement.

Upvotes: 1

Views: 639

Answers (1)

RationalGeek
RationalGeek

Reputation: 9599

Figured it out. Turns out the answer lies in the GetDescendant method. Calling this on the parent '/1/', passing '/1/1/' and '/1/2/' as the arguments, returns '/1/1.1/'.

Upvotes: 2

Related Questions