SQL Server hierarchyid - insert new node between two existing sibling nodes
NickName:RationalGeek Ask DateTime:2013-03-15T20:35:11

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.

Copyright Notice:Content Author:「RationalGeek」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15432635/sql-server-hierarchyid-insert-new-node-between-two-existing-sibling-nodes

More about “SQL Server hierarchyid - insert new node between two existing sibling nodes” related questions

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 betw...

Show Detail

How can I insert unique HierarchyId path without having to specify left and right sibling?

I am using HierarchyId in SQL to store the data. I am following the tutorial from here: http://www.codeproject.com/Tips/740553/Hierarchy-ID-in-SQL-Server The examples that are mentioned in the s...

Show Detail

SQL 2008 HierarchyID with Multiple Root Nodes

I wanted to use the new HierarchyID type in SQL Server 2008 to handle the page relations in a small wiki application. However It would need to have multiple root nodes since every main article/page...

Show Detail

Differences between SQL Server Hierarchyid and Entity Framework HierarchyId

I am seeing different behavior for the MS SQL Server Datatype hierarchyid, and the corresponding Entity Framework 6 class System.Data.Entity.Hierarchy.HierarchyId (from the assembly EntityFramework...

Show Detail

Is there any examples of storing social network graph in hierarchyid in sql server 2008

I have been investigating an approach towards to store our social graph data which obviously is going to be huge when time evolves. The graph is a bidirectional graph, meaning, two nodes are always

Show Detail

SQL Server HierarchyId and storing simple web navigation menu

We would like to store a simple web navigation menu in SQL Server 2012. This will be done for multiple clients, which is why we need it stored. The menu items also need to have a sequence, so they ...

Show Detail

Is hierarchyid suitable for large trees with frequent insertions of leaf nodes?

We have a database that models a tree. This data can grow fairly huge, that is to say many, may million of rows. (The primary key is actually a bigint, so I guess potentially we would like to support

Show Detail

Insert a node in between existing nodes

I have an insert method and I need help with inserting a new node between two nodes Here's the code: @Override public void insert(int index, E data) throws ListOverflowException { Node<E>...

Show Detail

Does SQL Server "NOT Allow" multiple roots?

I am very new to HierarchyId world and trying to implement HierarchyId() into my SQLServer design and I was under impression that SQL Server allows only one Root node per Column per table and if I ...

Show Detail

SQL join/merge two hierarchyid tables

Is there any way to join/merge two hierarchical tables in SQL Server? I have two sample tables: BOM and ComponentDetail declare @BOM table ( BomNode hierarchyid primary key,

Show Detail