Re: Update Parent-Child-Grandchild Table
From: Roji. P. Thomas (lazydragon_at_nowhere.com)
Date: 06/03/04
- Next message: Julie: "Update Parent-Child-Grandchild Table"
- Previous message: Tony C: "OSQL Question"
- In reply to: anonymous_at_discussions.microsoft.com: "Update Parent-Child-Grandchild Table"
- Next in thread: anonymous_at_discussions.microsoft.com: "Re: Update Parent-Child-Grandchild Table"
- Reply: anonymous_at_discussions.microsoft.com: "Re: Update Parent-Child-Grandchild Table"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 3 Jun 2004 14:17:12 +0530
Update what?
I am only seeing some Ids in the table!
Are you sure you only have to manage the
hierarchy with three levels? Is there the possibilty
of a fourth or fifth level.
To get some better ideas about managing hierarchies
google "Adjacent List model" and "Nested Set Model"
-- Roji. P. Thomas SQL Server Programmer <anonymous@discussions.microsoft.com> wrote in message news:1775301c44942$12564790$a301280a@phx.gbl... > Hi All > > I have a Parent-Child-Grandchild table as defined by the > DDL below. What is the most efficient way in order to > update the records as illustrated below: > > I am trying to update the parent at level 1 and then > update the child at level 2 and the grandchild at level > 3. I am also trying to update the parent at level 2 and > the child at level 3. > > Thanks in Advance for any assistance. > > ie. > > Lvl Parent Child GrandChild > ----------- ----------- ----------- ----------- > 1 123 NULL NULL > 2 12345 123 NULL > 3 1234567 12345 123 > 1 456 NULL NULL > 2 45678 456 NULL > 3 4567890 45678 456 > > Desired Result: > > Lvl Parent Child GrandChild > ----------- ----------- ----------- ----------- > 1 321 NULL NULL > 2 54321 321 NULL > 3 1234567 54321 321 > 1 654 NULL NULL > 2 87654 654 NULL > 3 4567890 87654 654 > > > > CREATE TABLE Data > ( > Lvl INT NOT NULL, > Parent INT NOT NULL, > Child INT, > GrandChild INT > ) > GO > > INSERT INTO Data SELECT 1, 123, NULL, NULL > INSERT INTO Data SELECT 2, 12345, 123, NULL > INSERT INTO Data SELECT 3, 1234567, 12345, 123 > > INSERT INTO Data SELECT 1, 456, NULL, NULL > INSERT INTO Data SELECT 2, 45678, 456, NULL > INSERT INTO Data SELECT 3, 4567890, 45678, 456
- Next message: Julie: "Update Parent-Child-Grandchild Table"
- Previous message: Tony C: "OSQL Question"
- In reply to: anonymous_at_discussions.microsoft.com: "Update Parent-Child-Grandchild Table"
- Next in thread: anonymous_at_discussions.microsoft.com: "Re: Update Parent-Child-Grandchild Table"
- Reply: anonymous_at_discussions.microsoft.com: "Re: Update Parent-Child-Grandchild Table"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|