hierarchyid

Updating “Hierarchyid” in SQL Server

泄露秘密 提交于 2019-12-04 18:18:36
I've used Hierarchyid data type in one of my tables in SQL Server. Now I want to change the father of one of the rows, but when I change that all its descendant HierarchyId's must change according to that. Is there a function to do that or I must change all of them myself. If I need to do that, what is the best way ? Thanks In advance 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]

Sql Hierarchy ID Sorting By Level

ぐ巨炮叔叔 提交于 2019-12-04 11:26:33
Is it possible to sort sql data in a hierarchy by it's hierarchy id, and then for each level sort it say alphabetically? So say we have an Employees Table that lists the organizational hierarchy based on the Employees ID You have Bob (5) who has Phil (17) and Charlie(28) Reporting to him, and Josie (6) has Tyler (15) and Mike (56) Reporting to her. If you sort it by HierarchyID it will look like: Bob (/5/) --Phil (/5/17/) --Charlie (/5/28/) Josie (/6/) --Tyler (/6/15/) --Mike (/6/56/) But It would probably make more sense to have it look like Bob --Charlie --Phil Josie --Mike --Tyler Is this

HierarchyID How to get all Parent from a child

前提是你 提交于 2019-12-04 06:04:31
i've a Problem with the hierarchyID and UserRights for a Menu. I only want to give the User the Right for Level 4 for example and my QUery should automaticly select all Parent from the Level 4 Child. How to do this ? Do you understand my Problem ? I simply want all Parents (ancestors) from a child. Greets Manuel Something like this avoides the CTE SELECT t1.NodeId.ToString(), t1.Name FROM (SELECT * FROM test_table2 WHERE Name = 'Node 1.1.1') t2 , test_table2 t1 WHERE t1.NodeId = t2.NodeId OR t2.NodeId.IsDescendantOf(t1.NodeId) = 1 I've been working a lot with HierarchyId lately and I came

Question about SQL Server HierarchyID depth-first performance

让人想犯罪 __ 提交于 2019-12-04 03:59:11
I am trying to implement hierarchyID in a table (dbo.[Message]) containing roughly 50,000 rows (will grow substantially in the future). However it takes 30-40 seconds to retrieve about 25 results. The root node is a filler in order to provide uniqueness, therefor every subsequent row is a child of that dummy row. I need to be able to traverse the table depth-first and have made the hierarchyID column (dbo.[Message].MessageID) the clustering primary key, have also added a computed smallint (dbo.[Message].Hierarchy) which stores the level of the node. Usage: A .Net application passes through a

SQL 2008 HierarchyID with Multiple Root Nodes

跟風遠走 提交于 2019-12-03 10:43:23
问题 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 per account would be a root node. From what I have read the HierarchyID type only allows 1 root node per column is this correct? and is there any way to enable multiple root nodes ? 回答1: Yes, you are reading right - using the HierarchyID allows only one single root node. That's the way it is and

HierarchyID: Get all descendants for a list of parents

醉酒当歌 提交于 2019-11-30 19:32:21
I have a list of parent ids like this 100, 110, 120, 130 which is dynamic and can change. I want to get all descendants for specified parents in a single set. To get children for a single parent I used such query: WITH parent AS ( SELECT PersonHierarchyID FROM PersonHierarchy WHERE PersonID = 100 ) SELECT * FROM PersonHierarchy WHERE PersonHierarchyID.IsDescendantOf((SELECT * FROM parent)) = 1 Have no idea how to do that for multiple parents. My first try was to write something like several unions, however I'm sure that there should be smarter way of doing this. SELECT * FROM PersonHierarchy

HierarchyID: Get all descendants for a list of parents

ぃ、小莉子 提交于 2019-11-30 03:13:44
问题 I have a list of parent ids like this 100, 110, 120, 130 which is dynamic and can change. I want to get all descendants for specified parents in a single set. To get children for a single parent I used such query: WITH parent AS ( SELECT PersonHierarchyID FROM PersonHierarchy WHERE PersonID = 100 ) SELECT * FROM PersonHierarchy WHERE PersonHierarchyID.IsDescendantOf((SELECT * FROM parent)) = 1 Have no idea how to do that for multiple parents. My first try was to write something like several

How do you get all ancestors of a node using SQL Server 2008 hierarchyid?

末鹿安然 提交于 2019-11-29 20:11:30
Given a table with a hierarchyid type column, how do you write a query to return all rows that are ancestors of a specific node? There is an IsDescendantOf() function, which is perfect for getting the children, but there's no corresponding IsAncestorOf() function to return ancestors (and the absence of a GetAncestors() function seems like quite an oversight.) The most commonly used approach would be a recursive Common Table Expression (CTE) WITH Ancestors(Id, [Name], AncestorId) AS ( SELECT Id, [Name], Id.GetAncestor(1) FROM dbo.HierarchyTable WHERE Name = 'Joe Blow' -- or whatever you need to

SQL 2008 HierarchyID support in NHibernate

佐手、 提交于 2019-11-29 03:05:03
Searched various NHibernate lists and haven't come up with a definitive answer. The SQL2008 dialect doesn't appear to have support for the HierarchyID data type - new date and time types only. Does anyone have a good implementation or an effective workaround? I'd really like to leverage HierarchyID in a new app of mine. Support for this interesting and powerful data type is sorely lacking in MS's own tools so I'm not shocked that NHibernate doesn't have support. There are some approaches out there that I haven't delved into yet. Wondering if anyone has some experience in what works, what is

HierarchyID in Entity Framework not working

Deadly 提交于 2019-11-28 17:19:52
We are using WCF Data Service based on an Entity Framework model for our application. In this we need to add the table with a column of type HierarchyId . When I add that table to the EDMX file, the HierarchId column is not appearing in the class file. What should I do to make use of HierarchyID ? I read that Entity Framework is not supporting HierarchyID , so how can I achieve this? You can always convert a HierarchyId to its string representation - something like /1/3/4/1 - and send that string across the WCF data service. Update: if you add this computed, persisted column to your SQL Server