Selecting All Parents In A Path Enumerated Tree

Jul 20, 2005

Hi,

I have a tree structure which is maintained through the use of a path
enumerated column:

CREATE TABLE items (
item_id NUMERIC NOT NULL,
path VARCHAR2(64) NOT NULL
);

The path is is a colon separated list of ids of the nodes of the tree.
So, for example, in this structure:

0 -> 1 -> 2 -> 3 -> 4

item id 4 would have a path of '0:1:2:3' (0 is the root of all
items, and does not actually exist). Notice that the path does not
include the item's own id.

I would like to select all of the items in a given item's path:

SELECT id, path FROM items WHERE id IN (PATH_TO_IDS(path));

or maybe:

SELECT id, path FROM items WHERE PATH_EQUALS(id, path));

or maybe something else altogether. This should return:

ITEM_ID PATH
------- -------
1 0
2 0:1
3 0:1:2
4 0:1:2:3

View 1 Replies


ADVERTISEMENT

Hierarchical (tree) Data Structure Where A Node Can Have Multiple Parents

May 9, 2008

Hi all!
I am trying to organize a hierarchical data structure into a table. I need to have the possibility to set 2 parents for some nodes. Curently I see following two options:
Example 1
id    parent_id    name-----------------------------------1     0                 Level 1 Parent A2     0                 Level 1 Parent B3     1,2              Level 2 Child
Example 2
id    parent_id    name-----------------------------------1     0                 Level 1 Parent A2     0                 Level 1 Parent B3     1                 Level 2 Child3     2                 Level 2 Child
Is any of the two examples valid database logic wise? In fact, is it possible to achieve the requirement by using only one table?
Thanks in advance,

View 4 Replies View Related

How Do I Write A Query To Get The Path From Ancestor To Node In A Tree?

Sep 12, 2005

Hi all. Here's my problem: I have a tree linking macaddresses (bigints)in a tree structure. i want to get the path from node a to b.create table tree1(father bigint , child bigint);insert into tree1 (father,child) values (100,200);insert into tree1 (father,child) values (100,300);insert into tree1 (father,child) values (100,400);insert into tree1 (father,child) values (200,2000);insert into tree1 (father,child) values (200,3000);insert into tree1 (father,child) values (100,4000);insert into tree1 (father,child) values (2000,11111);you can see that 100 --> 200 --> 2000 --> 11111select * from tree1what i would like is a query that given two parameters returns the pathbetweenthem, in the case of 100,11111 i want to get100200200011111if possible as different rows, but columns will do to.of course i do not know the legnth of the path. it can be very bigthx in advanceTzvika

View 3 Replies View Related

SQL 2012 :: Sort Tree Members In Right (tree) Structure?

Apr 6, 2015

I got assignment, how to make it appear in the right order .

/* DROP TABLE EMP
SELECT * INTO Emp FROM (
SELECT 'A' EmpID, NULL ManID, 'Name' EmpName UNION ALL
SELECT 'MAC' EmpID, 'A' ManID, 'Name__' EmpName UNION ALL
SELECT '1ABA' EmpID, 'MAC' ManID, 'Name____' EmpName UNION ALL
SELECT 'ABB' EmpID, '1ABA' ManID, 'Name______' EmpName UNION ALL
SELECT 'XB' EmpID, 'A' ManID, 'Name__' EmpName UNION ALL
SELECT 'BAC' EmpID, 'XB' ManID, 'Name____' EmpName ) b
*/

[code]....

View 2 Replies View Related

Multiple Parents For One Foreign Key

Jan 30, 2004

Hi,

I am trying to figure out if this is possible in Oracle or Mysql

Lets say I have 3 tables such that C could have either A or B as its parent.

A
{ id, name}

B
{id, name}

C
{other_id, comment}

Now other_id could be either A.id or B.id. What I want to be able to do is to define a foreign key constraint of the type:

CONSTRAINT FK_C FOREIGN KEY (other_id) REFERENCES A(id) ON DELETE CASCADE,
CONSTRAINT FK_C FOREIGN KEY (other_id) REFERENCES B(id) ON DELETE CASCADE

such that deleting A.id automatically deletes C.other_id where A.id = C.otherid and same for B.id

Ofcourse i am not able to do this. Is there any way that this can be done in Oracle and Mysql?

Thanks a lot,
Priyanka

View 2 Replies View Related

Query To Trace All Parents

Jul 23, 2005

Hi,I have a table with filled out below data:+------+-----+|parent|child|+------+-----+|A |B ||B |C ||B |E ||C |D ||E |F ||E |G |+------+-----+So I have to make a query which get all 'parent' values values forgiven child value.For example :-----------------If I have to get all parent values for 'D' child., query must get thisvalues : C, B, A.If I have to get all parent values for 'F' child., query must get thisvalues : E, B, A.If I have to get all parent values for 'C' child., query must get thisvalues : B, A.If I have to get all parent values for 'B' child., query must get thisvalues : A only.-----------------Is it possible to create a query which will covers all above conditionsor not using only sql statement without UDF or stored procedures.Any solutiuons?Sincerely,Rustam Bogubaev

View 3 Replies View Related

SQL XML :: How To Use Multi Sub Parents Using CDATA Tag

Oct 8, 2015

We have stored some special characters in our database and when we extract as XML Auto, Elements it through error illegal characters during import. I am looking and saw CDATA with Explicit option but don't know how to use it with multi tags like:

<1>
<12>
<23>
<34>
</34>
</23>
</12>
</1>

View 12 Replies View Related

Expanding Hierachy With Multiple Parents

Jul 20, 2005

I have a user assigned multiple roles and a role can be inherited frommultiple parents (see below). How do I answer such questions as "Howmany roles does the user belongs to?"I answered the above questions by using .NET but I think it can bemore efficient by using just SQL. I would appreciate if you can giveme an answer.Thank you.CREATE TABLE [dbo].[tb_User] ([Id] [int] IDENTITY (1, 1) NOT NULL PRIMARY KEY,[Name] nvarchar(99) NOT NULL UNIQUE,[Password] nvarchar(99) NOT NULL,) ON [PRIMARY]GOCREATE TABLE [dbo].[tb_Role] ([Id] [int] IDENTITY (1, 1) NOT NULL PRIMARY KEY,[Name] nvarchar(99) NOT NULL UNIQUE,) ON [PRIMARY]GOCREATE TABLE [dbo].[tb_User_Role] ([UserId] [int] NOT NULL ,[RoleId] [int] NOT NULL,) ON [PRIMARY]GOALTER TABLE [dbo].[tb_User_Role] WITH NOCHECK ADDCONSTRAINT [PK_tb_User_Role] PRIMARY KEY CLUSTERED([UserId],[RoleId]) ON [PRIMARY]GOCREATE TABLE [dbo].[tb_Parent_Role] ([RoleId] [int] NOT NULL ,[ParentRoleId] [int] NOT NULL ,) ON [PRIMARY]GOALTER TABLE [dbo].[tb_Parent_Role] WITH NOCHECK ADDCONSTRAINT [PK_tb_Parent_Role] PRIMARY KEY CLUSTERED([RoleId],[ParentRoleId]) ON [PRIMARY]GO

View 1 Replies View Related

Creating A Child Row With Two Parents? (in One Column)

Sep 29, 2006

Hi!

How can I make a relation that would let me relate an employee to two departments?

There is a table with emloyees and each one works in a department and there is a foreign key relation in the child (employees) table to the parent (departments) table. So can an employee work in two departments? (it's not impossible to imagine, is it?) And how would I retrieve all the employees of a department?

Or in other words, if I were working on some kind of software for my local supermarket and they need to keep track of all bills they ever gave out. I would make this products table and this bills table. Then I would create a foreign key column in the products table and fill it with bill_ids from the bills table and make retrieving bill items a simple getchildrow[](bill_row). Note that this is only an analogy, I need it done this way. How? (using C# express 2005, and SQL express and DataSets)

View 12 Replies View Related

Subject: BCM Install Error - Logfile &&amp; SQL Path Path &&amp; MSSQL.1?

Apr 16, 2008

When trying to install Business Contact Manager (BCM) for Outlook 2007, the setup failed and I was refered to a log file in my Local Settings/Temp folder. The log actually says that Business Contact Manager was installed sucessfully! BCM is supposed to install SQL Express 2005 as an instance or as instance if SQL Express is already installed. There is an MSSMLBIZ instance in Services..

Who can I send the Log File to for analysis and the fix feedback?

When I first went into Computer Management and clicked on Services and Applications in the left panel, the error message appeared "Snap-in failed to intialize. Name: SQL Server Configuration Manager CLSID:{CA9F8727-31DF-41D2-975C-887D84903967} This message diappeared when I clicked on Services and Applications again. Under Services, there are 3 SQL services - one is an application that was uninstalled 3-4 weeks ago and I disabled this service. The other 2 are: SQL Server (MSSMLBIZ) and the other one is SQL Server (SQLEXPRESS) When I tried to start either of the last 2, the message appeared: Services "Could not start the SQL Server (MSSMLBIZ) service on Local Computer. Error 3: The system cannot find the path specified. Under Program Files/Microsoft SQL Server/MSSGL.1 folder is mostly empty. So, it seems like the Path in the Registry is not valid and that nothing is being installed in the MSSQL.1 folder. If so, how do I fix this?

How do I get the BCM SQL instance to install and run properly? what do the messages in Services mean and how do I resolve these.

Thank you!

Gary

View 3 Replies View Related

SQL Server Not Starting - Tempdb Path Updated To Wrong Path

Oct 4, 2007

After updating TempDB path to a wrong path (without file name only folder name) the service is not starting. How can i sovle this and start the service

thanks

Leena

View 13 Replies View Related

Nested Subreport Causing The Parents Last Header To Expand. Why? How To Fix?

May 10, 2007

I have created a "parent" table with various columns and added an extra detail row to drop a nested subreport into the table passing parameters into the sub in order to obtain the child subreport. The problem is that the the while I can line up the columns in the sub report with the parent report,

I observe something like this:

parent columns:

a b c d e f

child columns

a b c d e f

The problem is in the last column of the parent "f" it appears stretched out for some reason-about an inch even though can grow is set to false.

Its like the child is forcing the parent's last column to expand yet when i observe the border around the table in the child the "f" is clearly more narrow than the parent's f despite my matching the column widths in the layout exactly the same . In preview mode, the parent's last column is extended width-about an inch more was added. Note I tested it with No data in the child's last column and it still expands the parent column by that inch.

Also note when I dropped the subreport into the parent report I'm merging the cells on the detail row that the subreport fits across columns a, b, c, d, e, f.

So even though the subreports data lines up properly under a, b, c, d, and e; the parent's "f" still expands outward.

Any clues or suggests on what I should consider changing. I'm stumped.

View 1 Replies View Related

How Can I Append Children To Parents In A SSIS Data Flow Task?

Apr 11, 2007

I need to extract data to send to an external agency in their supplied format. The data is normalised in our system in a one to many relationship. The external agency needs it denormalised.



In our system, the parent p has p_id, p_attribute_1, p_attribute_2, p_attribute_3 and the child has c_id, c_attribute_a, c_attribute_b, c_parent_id_fk



The external agency can only use a delimited file looking like

p_id, p_attribute_1, p_attribute_2, p_attribute_3, c1_attribute_a, c1_attribute_b, c2_attribute_a, c2_attribute_b, ...., cn_attribute_a, cn_attribute_b



where n is the number of children a parent may have. Each parent can have 0 or more children - typically between 1 and 20.



How can I achieve this using SSIS? In the past I have used custom built VB apps with the ADO SHAPE command but this is not ideal as I have to rebuild each time to alter the selection criteria and and VB is not a good SQL tool.

View 4 Replies View Related

Selecting The Most Recently Edited Item AND Selecting A Certain Type If Another Doesn't Exist

Sep 20, 2007

I've got a big problem that I'm trying to figure out:
I have an address table out-of-which I am trying to select mailing addresses for companies UNLESS a mailing address doesn't exist; then I want to select the physical addresses for that company. If I get multiple mailing or physical addresses returned I only want the most recently edited out of those.

I don't need this for an individual ID select, I need it applied to every record from the table.

My address table has some columns that look like:
[AddressID] [int]
[LocationID] [int]

[Type] [nvarchar](10)
[Address] [varchar](50)
[City] [varchar](50)
[State] [char](2)
[Zip] [varchar](5)
[AddDate] [datetime]
[EditDate] [datetime]

AddressID is a primary-key non-null column to the address table and the LocationID is a foreign key value from a seperate Companies table.
So there will be multiple addresses to one LocationID, but each address will have it's own AddressID.

How can I do this efficiently with perfomance in mind???

Thank you in advance for any and all replies...

View 2 Replies View Related

Reporting Services :: SSRS Recursive Parent Gives Distinct Children Only When Children Have Multiple Parents

Aug 18, 2015

I have made an SSRS report using the recursive parent functionality to show a hierarchical tree of values. The problem I have is that some children have more than one parent, but because (in order to use the recursive parent nicely) I need to group the results by Id, I only see distinct entries. This means that I only see each child once, even if it "should" appear in multiple locations in the report (under each of its parents).

View 6 Replies View Related

Tree

May 20, 2004

Dear all,

I would like to know how to create a single level hierachy structure in SQL.
Example, I have a single parent record in table A that may later on spawn one or child record in table B that relates back to the parent. It only needs a single level.
that means, one to many.

thanks and rgds.
Loke HC

View 1 Replies View Related

Tree

Jan 2, 2008

I have two tables.

table1 has 3 fields a , b and c. field "a" is a primary key.
table2 has 2 fields x and y. Fields x and y are nothing but the value of "a". Also, y is the child of x.
Therefore, x and y can never have same value. It means value of "a" either be child or parent.
But there is possibility that parent has no child.

Now, i wanted to write Select/Insert query for parent, b , c and child.

This tree is no a binary tree but N-Ary Tree.

Thanks,
sha


View 9 Replies View Related

Tree-walking In T-SQL

May 18, 2007

Hi,
 I'm having a major brain-failure moment here.
 Using T-SQL I want to be able to get all of the leaf nodes (e.g. nodes at the furthest end of a tree from the root) in a hierarchical relationship where the table structure is such NodeID|ParentID|NodeName.
 Basically if I had the following tree structure:
Root
    Child1
        Grandchild1
    Child2
        Grandchild2
 
I want to get all of the Grandchild nodes.  Number of levels will vary and I haven't got any kind of HasChilds column.
 I know this is possible because I remember having done it on a course years ago but I can't for the life of me figure it out on this sunny Friday afternoon.  I know it's going to involve either recursion, a while loop or cursors but my mind is currently jelly.  Can anyone help?

View 8 Replies View Related

How To Get All The Children In The MLM Tree..

Sep 10, 2007

hi. I am working on Multiline Marketing Project.I have to calculate all the childens and display the whole tree..I  have save records in tree format...But not able to calculate the all childrens.
SELECT count(*) FROM dfTree WHERE id in (SELECT id FROM dfTree WHERE lineage like '16%')
This query works properly.Problem is that it is not working in the project because  in the like I have to pass a variable.
SELECT count(*) FROM dfTree WHERE id in (SELECT id FROM dfTree WHERE lineage like '@idl%')
Please Suggest me...

View 1 Replies View Related

Need Help For Tree Functionality

Jun 2, 2008

HI,
 I am working on a Family tree portal which need tree functionality to display family members in tree structure. on click on any node the adding option should be displayed
for this i need a table and procedure to complete family tree
Thanks
@mbi

View 5 Replies View Related

Help Me Please, About Operator Tree

Jan 3, 2006

Consider the following SQL query:
SELECT ENAME,SAL
FROM EMP,ASG,PAY,PROJ
WHERE EMP.ENO=ASG.ENO
AND PAY.TITLE=EMP.TITLE
AND ASG.PNO=PROJ.PNO
AND ASG.DUR=48 AND BUDGET>200000
Give the possible operator trees:right-deep,left-deep and bush
Tank you very much!

View 2 Replies View Related

Tree Structures In SQL

Jun 11, 2006

Hi,

i'm writing a app in c# and have to store Trees in a Database.

I'm working with Datasets for the exchange between the DB and the App.

The trees have the same options like the windows folders. If u delete a node, all subnodes should be deleted too.

But something a Foreign Key from ParentID references (Id) with the delete-Rule on cascade seems not to be possible, because of multiple cascade Paths or cycles. Do i have to add some xtra constarins:

Not Possible:

create Table tree (
Id varchar Not null,
ParentId varchar Not null,
Constraint pk1 Primary Key (Id),
Constraint fk1 Foreign Key (ParentId) references tree(Id)
On Update Cascade
On delete CAscade
)


Do i have to write triggers, which delete The subnodes too and set the Update-/deleterulr on NO Action

Greetz

View 1 Replies View Related

Tree Structures...

Oct 24, 2006

Does anyone know any good links for SQL tree structures and example queries and stuff... I cant really find anything part from the standard example of emplyee, boss, salary which explains how to create the tree table...(dun dis bit) I did notice a book but I live in a little village so cant go get it till wekend?

I'm desperate, reli need to work out how too do this.....

View 14 Replies View Related

Tree Selection

Jun 13, 2008

SELECT a.Network_ID, b.Last_Name + ', ' + b.Preferred_FirstName AS full_name, c.Security_Class_Description,
d.Security_Type_Description, a.Security_Value
FROM Company_Hierarchy_Security a
JOIN V_Entity_Employee_Active b on a.Network_ID= b.Network_ID
JOIN Company_Security_Class c on a.Security_Class_Code=c.Security_Class_Code
JOIN Company_Security_Type d on a.Security_Type = d.Security_Type
inner join (select e.Budget_Center_ID + ' - ' + e.Budget_Center_Description As Budget_Center_Description,
f.Company_Name, g.Enterprise_Description, h.Business_Segment_Description,
i.Team_Description
from Company_Hierarchy_Security a.
Inner JOIN Budget_Center e on a.Security_Value = e.Budget_Center_ID
Inner JOIN Company f on a.Security_Value = f.Company_ID
Inner JOIN Enterprise g ON a.Security_Value = Cast(g.Enterprise_Number As Varchar(5))
Inner JOIN Business_Segment h on a.Security_Value = h.Business_Segment_ID
Inner JOIN Team i on a.Security_Value = i.Team_ID


Ok. I have the Security Value located in Company_Hierarchy_Security table. All those values are divided into 5 other tables that I need to join together. I found all of them separate but I have not been able to figue it out how to put it together with the rest of the querie.

Thanks for the help!!!!!

View 3 Replies View Related

Tree Selection

Jun 16, 2008

Thank You visakh16 --- The following section of my querie works but doesn't give the exact information that I need. This is what is giving me:

NetworkId Full Name Sec Class Desc Sec Type Desc SecValue
tte Test Scenario Accounting Budget Center 142- ?



SELECT a.Network_ID, b.Last_Name + ', ' + b.Preferred_FirstName AS full_name, c.Security_Class_Description,
d.Security_Type_Description, a.Security_Value
FROM Company_Hierarchy_Security a
JOIN V_Entity_Employee_Active b on a.Network_ID= b.Network_ID
JOIN Company_Security_Class c on a.Security_Class_Code=c.Security_Class_Code
JOIN Company_Security_Type d on a.Security_Type = d.Security_Type

------------------

inner join (select e.Budget_Center_ID + ' - ' + e.Budget_Center_Description As Budget_Center_Description,
f.Company_Name, g.Enterprise_Description, h.Business_Segment_Description,
i.Team_Description
from Company_Hierarchy_Security a.
Inner JOIN Budget_Center e on a.Security_Value = e.Budget_Center_ID
Inner JOIN Company f on a.Security_Value = f.Company_ID
Inner JOIN Enterprise g ON a.Security_Value = Cast(g.Enterprise_Number As Varchar(5))
Inner JOIN Business_Segment h on a.Security_Value = h.Business_Segment_ID
Inner JOIN Team i on a.Security_Value = i.Team_ID

_____________________________________________________________________

What I need is the Description that are located in 4 other different tables that matches the Security Value from my first querie.

The result should look like this...

Network Id full Name Sec Class Desc Sec Type Desc Security Value
tst , Test Example , Accounting ,Budget Center , 142-Accountig dept


Thank you very much,

View 4 Replies View Related

Organization Tree

Oct 14, 2005

Any recomendations on how to store organization trees on a database withlots of paths and branches? Any white papers out there that explain this?Thanks

View 2 Replies View Related

Tree Table

Sep 12, 2006

Hello,I have a "tree" table:Id - primary keyParrentId - (foreign key) related to IdTitle.....when I delete some record I want to delete it with all childs (cascadedeleting). I can't set cascade deleting on the same table :(. Is thereany easy way in the MSSQL 2005 to do this ? There is one idea - usingcursors + recursive functions but I think this solution is not easyand elegant.Thakns for any help and sugestions.Regards.Andy

View 4 Replies View Related

Tree View

Mar 5, 2008

Hi:

Is there a resource or an object in Reporting Services that I could make a tree view in a report file .rdl and see the result on it?

If not, is there a software of MS that a could make a component for it, and connect this component in the report file .rdl ?

View 6 Replies View Related

PLZ HELP ME WITH THE DECISION TREE!!

Apr 16, 2007

I'm having this problem.....



I wanted to use the Decision Tree to show a result..... after i configure the Mining Structures..... and set all the input.... my decision tree shows only until level 2..... i have 3 input and one PredictOnly column.....where is the other input?



Say.... i have House Owner, Marital Status, Num Cars Owned and Number Of Children(PredictOnly)



my Tree only shows All ---- > Marital Status when i input all 3 together...... the other 2 doesn't seems to show.



wat should i do?? my database in SQL Server and the other keys are all correct and deploying finely.....why is this happening.....?



i'm a newbie in this software.......so any pro here can plz help me if there's actually something that i might have missed out along the way.......



Thank you again.........

View 1 Replies View Related

Rescursive Tree

Feb 28, 2008



Alright what im trying to do is build a classic tree, i have id's like this set up in my table referencing itself in sql 2000


cmponent_prt_no parent_part_no
--------------- --------------
112837A2A L115100-1
114379A1A L115100-1
115623A1A L115100-1
203604A L115100-1
203790A L115100-1
203791A L115100-1
115623A 115623A1A
M010137 115623A1A
115623A 115623A1A
20766CR 115623A1A
DRAWINGS 20766CR
M010137 20766CR

i have tried 3 different solutions all coming to a crash at some point, if ANYONE can help me out i would appreciate it, i know the logic will be recursive, i just dont know how to implement

View 8 Replies View Related

Convert A Table Into Tree

Aug 21, 2007

Hi..I have a table  register..in this fields are username,parent id,downline ; I have to determine all the child of a particular parent.
suppose table is like this.  username   parentid        downline
                                         B                A                left
                                         C               A                 right
                                         D                B               left
                                         E                B               right....
I have to also determine the level in the tree....please help...

View 1 Replies View Related

Does Anyone Know How To Traverse A Simple Tree Using SQL?

Dec 6, 2000

Hello all!

I have a table defined as:

create table OrgTree (parent int, child int)

OrgTree has the following data:

1,2
1,3
2,4
2,5
3,6
4,7
4,8
8,9

Is there a SQL stmt that will return, given a particlar parent, all of the children (and children's children, etc.) of that parent?

So, parent value 1 returns 2,3,4,5,6,7,8,9
parent value 2 returns 4,5,7,8,9
parent value 3 returns 6
etc.

Thanks in advance for your help!!

Palmer F

View 1 Replies View Related

Database Tree Says &#39;No Items&#39; ???

Oct 30, 2001

I just started having this problem. When I log into SQL2000 enterprise manager and click on my database, the main directory tree shows up. When I click on the Database tree to display all of the different databases on the SQL server, the text 'No Items' shows up. I can not get to any databases, but I am connected to the SQL server. Does anyone have a solution for this problem?????

I have tried re-inatalling and all of the service packs.

Thanks !!

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved