Questions tagged [hierarchyid]

hierarchyid is a TSQL extension available from SQL Server 2008 to map hierarchical structures in a flat table. It supports in-order-sorting, get-descendant and level-queries

hierarchyid is a TSQL extension available from SQL Server 2008 to map hierarchical structures in a flat table. It supports in-order-sorting, get-descendant and level-queries

152 questions
2
votes
1 answer

How to Create Script for hierarchyid datatype for below data?

Can you please help me regarding my hierarchyid datatype column as orgpath? I have a table called companies, in that companyid, parentcompany_id, companyName are the fields I need to create the "orgpath" as hierarchyid. declare @Companies table ( …
Krishna M
  • 43
  • 6
2
votes
1 answer

Populate hierarchyid column in existing parent-children relationship table?

I search for a way to populate an existing parent-children table: Tabelle: Categories ------------------- Columns: CategoryID ParentID I upgrade my sql server to 2008 R2. And now i added the new hierarchyid-datatype to optimize the…
2
votes
1 answer

Using SqlHierarchId throws System.InvalidCastException with Dapper

I want to use SqlHierarchId in my .net project but when I try to read a SqlHierarchId from DB, System.InvalidCastException will occur. I have written a simple code which it's accessible in bellow link, to show this problem: SqlHierarchyIdTest var…
Fred
  • 3,365
  • 4
  • 36
  • 57
2
votes
2 answers

Hierarchyid Problem

I have a table with hierarchyid column. It is like: [NAME] [PATH] Ahmet / Aliye /1/ Selen /1/1/ Erdem /2/ Bilge /2/1/ Aydin /2/2/ Tomrs /2/2/2/ I want to see NAMES…
ogun
  • 1,314
  • 2
  • 16
  • 40
2
votes
3 answers

Get the parent SQL Server variable hierarchyid

How to get the parent node in a table using the variable of the variable of type hierarchyid in sql by id(EmployeeID)? this is my table CREATE TABLE Employee ( Node hierarchyid PRIMARY KEY CLUSTERED, EmployeeID int UNIQUE NOT NULL, …
2
votes
1 answer

Ordering by HierarchyId but with parent first

In one of our databases we use a HierarchyId column. We then select the rows from the table like this: SELECT HierarchyId.ToString() FROM Tree ORDER BY HierarchyId DESC This lays it out in a nice hierarchical structure but with all of the nodes…
JoeS
  • 1,405
  • 17
  • 30
2
votes
1 answer

Support of HierarchyId in C#?

I have just started working with hierarchyId in Sql Server. I am looking at different functionalities in SQL server. However, this sounds to me like a call to very thick data layer, which I want to avoid. Is there any API in C# for HierarchyId type…
Lost
  • 12,007
  • 32
  • 121
  • 193
2
votes
1 answer

How to Insert auto-generated identity value as part of a hierarchyid field on the same record

I am trying to find a way to insert a record into a table that uses the newly generated Identity value as part of it's hierarchy id. The following sql demonstrates what I am trying to do, and the closest I have managed to come. Which is to use an…
Matthew Vines
  • 27,253
  • 7
  • 76
  • 97
2
votes
1 answer

SQL 2008 HierarchyID - Select X descendants down

How can I query a table which has a column of data type HIERARCHYID and get a list of descendants X levels deep under an employee? Here is the current structure: CREATE TABLE [dbo].[Employees]( [NodeId] [hierarchyid] NOT NULL, [EmployeeId]…
IEnumerator
  • 2,960
  • 5
  • 31
  • 33
2
votes
2 answers

SqlHierarchyID casting from Datarow

I am trying to retrieve a SqlHierarchyID data-type in C#, from a DataRow that has been fetched from a SQL Server database. After the database call, if I write the following: var id = datarow["TreeID"]; And then inspect the value of id using a watch…
J T
  • 4,946
  • 5
  • 28
  • 38
2
votes
2 answers

HierarchyId Has Descendants Query

Given the following schema and data: CREATE TABLE ##Nodes ( NodeCode hierarchyid, NodeName varchar(10) ) INSERT INTO ##Nodes VALUES ('/','RootNode') INSERT INTO ##Nodes VALUES ('/1/','Node1') INSERT INTO ##Nodes VALUES…
B Z
  • 9,363
  • 16
  • 67
  • 91
2
votes
1 answer

HierarchyId in KendoUI TreeView

i am new to KendoUI so i was wondering if/how i can use data represented with the new HierarchyId datatype in my sql server database in my KendoUI TreeView. Are there any suggestions on how to approach this?
r3try
  • 667
  • 8
  • 20
2
votes
1 answer

How to Populate a Set Collection of Children from HierarchyId in nHibernate

I have the parent side of the mapping, but am unsure how to properly map the children side. Parent Mapping ( SELECT o.`ou_id` FROM…
roydukkey
  • 3,149
  • 2
  • 27
  • 43
2
votes
3 answers

SQL Server INNER JOIN with hierarchyid

I have two tables, one table is the items container, which holds all data related to the products. The other table is for categories, in which the data is organised using hierarchies. The goal of the query is to list items that match the category…
Carlos
  • 23
  • 5
2
votes
3 answers

How to build object hierarchy from SQL query? (for WPF TreeView)

thanks for taking the time out to read this post. I'm having trouble trying to build a hierarchial object when getting data from my SQL database. Please note that I am a little bit of a newbie programmer. How do you build a hierarchial object that…
RobHurd
  • 2,041
  • 7
  • 26
  • 34